home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / physics.bst < prev    next >
Lisp/Scheme  |  1990-10-02  |  99KB  |  3,521 lines

  1. %NAME: physics.bst
  2. % BibTeX styles for various physics journals.
  3. % This file, physics.bst, is based on the file btxbst.doc.
  4.         % Please notify Charles Karney (Karney%PPC.MFEnet@NMFECC.ARPA)
  5.         % of any bugs, improvements, etc.
  6.  
  7. % Run this file through cpp to get specific versions.  I have written
  8. % a version of cpp within Emacs.  To access it put
  9. %       (autoload 'cpp "tex$bibtex:cpp"         ; Use cpp for BibTeX styles
  10. %                 "C preprocessor"
  11. %                 t)
  12. % into your .emacs file.  Read in this file with
  13. %       emacs tex$bibtex:physics.bst
  14. % and run cpp with e.g.,
  15. %       M-x cpp <ret> aip <ret>
  16. % Save the resulting file to tex$latex:aip.bst.
  17.  
  18. % To accomodate the variations we need (in addition to the definitions below)
  19. %       ATIT_SUPPRESS:  do not include the titles of journal articles
  20. %       NAME_INVERT:    put the initials last
  21. %       NAME_UPPER:     convert names to all caps.
  22. %       MONTH_SUPPRESS: do not include months in journal articles
  23. %       PAREN_DATE:     dates go in parens in journal articles
  24. %       DATE_FIRST:     dates go before page numbers
  25. %       VOLUME_SPACE:   volume set off with space (not colon)
  26. %       NUM_SUPPRESS:   do not include numbers in journal articles
  27. %       BOLD_VOL:       volume numbers in bold face in journal articles
  28. %       BRACKET_NOTE:   notes in brackets
  29. %       PAGE_START_J:   include only starting page for journal articles
  30. %       PAGE_START_O:   include only starting page for other entries
  31. %       PAGE_ABBREV:    abbreviate page to p. and pages to pp.
  32. %       PHYSICS_JOUR:   include abbreviations for Physics journals
  33. %       COMMA_DELIMIT:  use comma (instead of period) to divide a citation
  34. %       NOTE_SUPPRESS:  suppress the note
  35. %       NOTE_BRACKET:   put note in brackets
  36. %       MAX_NAMES:      max number of authors before using et al (0 = infinity)
  37. %       MIN_NAMES:      number of authors to list with et al.
  38. %       EDIT_VAR:       use "edited by ..." instead of "..., editors"
  39. %       RMP_LABELS:     create RMP-style labels
  40. %       KEY_CITE:       use key as label
  41. %       NAMED_REFS:     use (Smith, 1988) style of citations
  42. %       CSC_NAMES:      names set in caps and small caps
  43. %       JOUR_DEEMPH:    don't emphasize journal name
  44. %       ETAL_EMPH:      emphasize et al.
  45.  
  46. % These are all boolean (0 or 1) except for MAX_NAMES and MIN_NAMES.
  47. % These need to satisfy 0 <= MIN_NAMES <= MAX_NAMES.
  48. % The rule here is that if all these are defined to be zero, we revert to
  49. % the standard styles.  For that reason we initialize them all to 0.
  50.  
  51. #   define ATIT_SUPPRESS 0
  52. #   define NAME_INVERT 0
  53. #   define NAME_UPPER 0
  54. #   define MONTH_SUPPRESS 0
  55. #   define PAREN_DATE 0
  56. #   define DATE_FIRST 0
  57. #   define VOLUME_SPACE 0
  58. #   define NUM_SUPPRESS 0
  59. #   define BOLD_VOL 0
  60. #   define BRACKET_NOTE 0
  61. #   define PAGE_START_J 0
  62. #   define PAGE_START_O 0
  63. #   define PAGE_ABBREV 0
  64. #   define PHYSICS_JOUR 0
  65. #   define COMMA_DELIMIT 0
  66. #   define NOTE_SUPPRESS 0
  67. #   define NOTE_BRACKET 0
  68. #   define MAX_NAMES 0
  69. #   define MIN_NAMES 0
  70. #   define EDIT_VAR 0
  71. #   define RMP_LABELS 0
  72. #   define KEY_CITE 0
  73. #   define NAMED_REFS 0
  74. #   define CSC_NAMES 0
  75. #   define JOUR_DEEMPH 0
  76. #   define ETAL_EMPH 0
  77.  
  78. % These are the original macros
  79. #   define LAB_ALPH 0
  80. #   define SORTED 0
  81. #   define NAME_FULL 0
  82. #   define ATIT_LOWER 0
  83. #   define MONTH_FULL 0
  84. #   define JOUR_FULL 0
  85.  
  86. #ifdef AIP
  87.         % For American Institute of Physics Journals
  88. #   define ATIT_SUPPRESS 1
  89. #   define PAGE_START_J 1
  90. #   define PHYSICS_JOUR 1
  91. #   define MAX_NAMES 5
  92. #   define MIN_NAMES 1
  93. #   define EDIT_VAR 1
  94. #   define ATIT_LOWER 1
  95. #   define COMMA_DELIMIT 1
  96. #   define VOLUME_SPACE 1
  97. #   define MONTH_SUPPRESS 1
  98. #   define PAREN_DATE 1
  99. #   define NUM_SUPPRESS 1
  100. #   define BOLD_VOL 1
  101. #   define JOUR_DEEMPH 1
  102. #endif
  103. #ifdef NF
  104.         % For Nuclear Fusion
  105. % same as AIP except for NAME_INVERT, NAME_UPPER, DATE_FIRST and 
  106. %  MIN_NAMES and MAX_NAMES set to 0 (infinity)
  107. #   define ATIT_SUPPRESS 1
  108. #   define PAGE_START_J 1
  109. #   define PHYSICS_JOUR 1
  110. #   define EDIT_VAR 1
  111. #   define ATIT_LOWER 1
  112. #   define COMMA_DELIMIT 1
  113. #   define VOLUME_SPACE 1
  114. #   define MONTH_SUPPRESS 1
  115. #   define PAREN_DATE 1
  116. #   define NUM_SUPPRESS 1
  117. #   define BOLD_VOL 1
  118. #   define NAME_INVERT 1
  119. #   define NAME_UPPER 1
  120. #   define DATE_FIRST 1
  121. #   define JOUR_DEEMPH 1
  122. #endif
  123. #ifdef NFLET
  124.         % For Nuclear Fusion Letters
  125. % same as NF except for MIN_NAMES and MAX_NAMES set to 5
  126. #   define ATIT_SUPPRESS 1
  127. #   define PAGE_START_J 1
  128. #   define PHYSICS_JOUR 1
  129. #   define EDIT_VAR 1
  130. #   define ATIT_LOWER 1
  131. #   define COMMA_DELIMIT 1
  132. #   define VOLUME_SPACE 1
  133. #   define MONTH_SUPPRESS 1
  134. #   define PAREN_DATE 1
  135. #   define NUM_SUPPRESS 1
  136. #   define BOLD_VOL 1
  137. #   define NAME_INVERT 1
  138. #   define NAME_UPPER 1
  139. #   define DATE_FIRST 1
  140. #   define MAX_NAMES 5
  141. #   define MIN_NAMES 5
  142. #   define JOUR_DEEMPH 1
  143. #endif
  144. #ifdef IAEA
  145.         % For IAEA Conferences
  146. % same as NF except for MIN_NAMES and MAX_NAMES set to 1
  147. #   define ATIT_SUPPRESS 1
  148. #   define PAGE_START_J 1
  149. #   define PHYSICS_JOUR 1
  150. #   define EDIT_VAR 1
  151. #   define ATIT_LOWER 1
  152. #   define COMMA_DELIMIT 1
  153. #   define VOLUME_SPACE 1
  154. #   define MONTH_SUPPRESS 1
  155. #   define PAREN_DATE 1
  156. #   define NUM_SUPPRESS 1
  157. #   define BOLD_VOL 1
  158. #   define NAME_INVERT 1
  159. #   define NAME_UPPER 1
  160. #   define DATE_FIRST 1
  161. #   define MAX_NAMES 1
  162. #   define MIN_NAMES 1
  163. #   define JOUR_DEEMPH 1
  164. #endif
  165. #ifdef CPC
  166.         % For Computer Physics Communications
  167. % same as AIP except for NAME_INVERT, DATE_FIRST
  168. #   define ATIT_SUPPRESS 1
  169. #   define PAGE_START_J 1
  170. #   define PHYSICS_JOUR 1
  171. #   define MAX_NAMES 5
  172. #   define MIN_NAMES 1
  173. #   define EDIT_VAR 1
  174. #   define ATIT_LOWER 1
  175. #   define COMMA_DELIMIT 1
  176. #   define VOLUME_SPACE 1
  177. #   define MONTH_SUPPRESS 1
  178. #   define PAREN_DATE 1
  179. #   define NUM_SUPPRESS 1
  180. #   define BOLD_VOL 1
  181. #   define NAME_INVERT 1
  182. #   define DATE_FIRST 1
  183. #   define JOUR_DEEMPH 1
  184. #endif
  185. #ifdef RMP
  186.         % For Reviews of Modern Physics, 
  187. % except first name not inverted yet and order of fields not hacked
  188. #   define LAB_ALPH 1
  189. #   define SORTED 1
  190. #   define RMP_LABELS 1
  191. #   define ATIT_SUPPRESS 1
  192. #   define ATIT_LOWER 1
  193. #   define MONTH_SUPRESS 1
  194. #   define NUM_SUPPRESS 1
  195. #   define VOL_SUPPRESS 1
  196. #   define BOLD_VOL 1
  197. #   define BRACKET_NOTE 1
  198. #   define PAGE_START_J 1
  199. #   define PAGE_START_O 1
  200. #   define PAGE_ABBREV 1
  201. #   define PHYSICS_JOUR 1
  202. #   define COMMA_DELIMIT 1
  203. #   define EDIT_VAR 1
  204. #   define JOUR_DEEMPH 1
  205. #endif
  206. #ifdef REPORT
  207.         % For internal reports
  208. % same as AIP except for ATIT_SUPPRESS, MONTH_SUPPRESS, PAGE_START_J,
  209. % NUM_SUPPRESS, MAX_NAMES, MIN_NAMES
  210. #   define PHYSICS_JOUR 1
  211. #   define EDIT_VAR 1
  212. #   define ATIT_LOWER 0
  213. #   define COMMA_DELIMIT 1
  214. #   define VOLUME_SPACE 1
  215. #   define PAREN_DATE 1
  216. #   define BOLD_VOL 1
  217. #   define JOUR_DEEMPH 1
  218. #endif
  219. #ifdef APALIKE
  220.         % For American Psychological Association
  221.         % (same as ALPHA but with NAMED_REFS set and NAME_FULL unset)
  222. #   define LAB_ALPH 1
  223. #   define SORTED 1
  224. #   define NAME_FULL 0
  225. #   define ATIT_LOWER 1
  226. #   define MONTH_FULL 1
  227. #   define JOUR_FULL 1
  228. #   define NAMED_REFS 1
  229. #   define NAME_INVERT 1
  230. #endif
  231. #ifdef PPCF
  232.         % A physics version of APALIKE
  233. #   define PHYSICS_JOUR 1
  234. #   define LAB_ALPH 1
  235. #   define SORTED 1
  236. #   define NAME_FULL 0
  237. #   define ATIT_LOWER 0
  238. #   define ATIT_SUPPRESS 1
  239. #   define MONTH_FULL 1
  240. #   define JOUR_FULL 0
  241. #   define NAMED_REFS 1
  242. #   define NAME_INVERT 1
  243. #   define ETAL_EMPH 1
  244. #   define CSC_NAMES 1
  245. #   define NUM_SUPPRESS 1
  246. #   define BOLD_VOL 1
  247. #   define VOLUME_SPACE 1
  248. #endif
  249.  
  250. % This is the start of btxbst.doc
  251.  
  252. % BibTeX `plain' family
  253.         % version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  254.         % Copyright (C) 1985, all rights reserved.
  255.         % Copying of this file is authorized only if either
  256.         % (1) you make absolutely no changes to your copy, including name, or
  257.         % (2) if you do make changes, you name it something other than
  258.         % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  259.         % This restriction helps ensure that all standard styles are identical.
  260.         % The file btxbst.doc has the documentation for this style.
  261. #if NAMED_REFS
  262. % BibTeX `apalike' bibliography style (24-Jan-88 version)
  263. % Adapted from the `alpha' style, version 0.99a; for BibTeX version 0.99a.
  264. % Copyright (C) 1988, all rights reserved.
  265. % Copying of this file is allowed, provided that if you make any changes at all
  266. % you name it something other than `apalike.bst'.
  267. % This restriction helps ensure that all copies are identical.
  268. % Differences between this style and `alpha' are generally heralded by a `%'.
  269. % The file btxbst.doc has the documentation for alpha.bst.
  270. %
  271. % This style should be used with the `apalike' LaTeX style (apalike.sty).
  272. % \cite's come out like "(Jones, 1986)" in the text but there are no labels
  273. % in the bibliography, and something like "(1986)" comes out immediately
  274. % after the author.  Author (and editor) names appear as last name, comma,
  275. % initials.  A `year' field is required for every entry, and so is either
  276. % an author (or in some cases, an editor) field or a key field.
  277. %
  278. % Editorial note:
  279. % Many journals require a style like `apalike', but I strongly, strongly,
  280. % strongly recommend that you not use it if you have a choice---use something
  281. % like `plain' instead.  Mary-Claire van Leunen (A Handbook for Scholars,
  282. % Knopf, 1979) argues convincingly that a style like `plain' encourages better
  283. % writing than one like `apalike'.  Furthermore the strongest arguments for
  284. % using an author-date style like `apalike'---that it's "the most practical"
  285. % (The Chicago Manual of Style, University of Chicago Press, thirteenth
  286. % edition, 1982, pages 400--401)---fall flat on their face with the new
  287. % computer-typesetting technology.  For instance page 401 anachronistically
  288. % states "The chief disadvantage of [a style like `plain'] is that additions
  289. % or deletions cannot be made after the manuscript is typed without changing
  290. % numbers in both text references and list."  LaTeX sidesteps the disadvantage.
  291. %
  292. % History:
  293. %   15-sep-86   (SK,OP) Original version, by Susan King and Oren Patashnik.
  294. %   10-nov-86   (OP)    Truncated the sort.key$ string to the correct length
  295. %                       in bib.sort.order to eliminate error message.
  296. %   24-jan-88   (OP)    Updated for BibTeX version 0.99a, from alpha.bst 0.99a;
  297. %                       apalike now sorts by author, then year, then title;
  298. %                       THIS `apalike' VERSION DOES NOT WORK WITH BIBTEX 0.98i.
  299. #endif APALIKE
  300. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  301. % these standard styles or in this documentation file.
  302. %
  303. % This is file btxbxt.doc; it helps document bibliography styles,
  304. % and is also a template file that you can use to make
  305. % several different style files, if you have access to a C preprocessor.
  306. % For example, the standard styles were made by doing something like
  307. %       cpp -P -DPLAIN btxbst.doc plain.txt
  308. %       cpp -P -DUNSRT btxbst.doc unsrt.txt
  309. %       cpp -P -DALPHA btxbst.doc alpha.txt
  310. %       cpp -P -DABBRV btxbst.doc abbrv.txt
  311. % and then renaming after removing unwanted comments and blank lines.
  312. % If you don't have access,
  313. % you can edit this file by hand to imitate the preprocessor,
  314. % with the following explanation of the C preprocessor constructs used here.
  315. %
  316. % The output of the preprocessor is the same as the input, except that certain
  317. % lines will be excluded (and some blank lines will be added).  The sequence
  318. %       #if VAR
  319. %           lines to be included when VAR is not zero
  320. %       #else
  321. %           lines to be included when VAR is zero
  322. %       #endif
  323. % (with the #-signs appearing in column 1) means that one set or the other of
  324. % the lines are to be included depending on the value of VAR.
  325. % The #else part is optional.  Comments can be added after #else and #endif.
  326. % Variables can be set by
  327. %       #define VAR value
  328. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  329. % to see if it has none.
  330. % Another #if form used in this file is #if !VAR, which includes the lines
  331. % after the #if only if VAR is zero.
  332. %
  333. % Convention: Use all uppercase identifiers for these preprocessor variables
  334. % so you can spot them easily
  335. %
  336. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  337. % or ABBRV (though PLAIN will be used by default if none is given),
  338. % and the following lines will set various boolean variables to control the
  339. % various lines that are chosen from the rest of the file.
  340. % Each boolean variable should be set true (1) or false (0) in each style.
  341. % Here are the current variables, and their meanings:
  342. %       LAB_ALPH:       an alphabetic label is used (if false then a numeric
  343. %                           label is used)
  344. %       SORTED:         the entries should be sorted by label (if nonnumeric)
  345. %                           and other info, like authors (if false, then
  346. %                           entries remain in order of occurrence)
  347. %       NAME_FULL:      the authors, editors, etc., get the full names as
  348. %                           given in the bibliography file (if false, the first
  349. %                           names become initials)
  350. %       ATIT_LOWER:     titles of non-"books" (e.g., articles) should be
  351. %                           converted to lower-case, except the first letter or
  352. %                           first letter after a colon
  353. %                           (if false then they appear as in the database)
  354. %       MONTH_FULL:     months are spelled out in full (if false, then
  355. %                           they're abbreviated)
  356. %       JOUR_FULL:      macro journal names are spelled out in full
  357. %                           (if false then they are abbreviated, currently
  358. %                           as they appear in ACM publications)
  359. #ifndef UNSRT
  360. #   ifndef ALPHA
  361. #       ifndef ABBRV
  362. %#          define PLAIN 1
  363. #       endif
  364. #   endif
  365. #endif
  366. #ifdef PLAIN
  367. % plain style (sorted numbers)
  368. #   define LAB_ALPH 0
  369. #   define SORTED 1
  370. #   define NAME_FULL 1
  371. #   define ATIT_LOWER 1
  372. #   define MONTH_FULL 1
  373. #   define JOUR_FULL 1
  374. #endif
  375. #ifdef UNSRT
  376. % unsrt style (unsorted numbers)
  377. #   define LAB_ALPH 0
  378. #   define SORTED 0
  379. #   define NAME_FULL 1
  380. #   define ATIT_LOWER 1
  381. #   define MONTH_FULL 1
  382. #   define JOUR_FULL 1
  383. #endif
  384. #ifdef ALPHA
  385. % alpha style (sorted short alphabetics)
  386. #   define LAB_ALPH 1
  387. #   define SORTED 1
  388. #   define NAME_FULL 1
  389. #   define ATIT_LOWER 1
  390. #   define MONTH_FULL 1
  391. #   define JOUR_FULL 1
  392. #endif
  393. #ifdef ABBRV
  394. % abbrv style (sorted numbers, with abbreviations)
  395. #   define LAB_ALPH 0
  396. #   define SORTED 1
  397. #   define NAME_FULL 0
  398. #   define ATIT_LOWER 1
  399. #   define MONTH_FULL 0
  400. #   define JOUR_FULL 0
  401. #endif
  402. %
  403. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  404. %       in "A Handbook for Scholars".  Book-like titles are italicized
  405. %       (emphasized) and non-book titles are converted to sentence
  406. %       capitilization (and not enclosed in quotes).
  407. %       This file outputs a \newblock between major blocks of an entry
  408. %       (the name \newblock is analogous to the names \newline and \newpage)
  409. %       so that the user can obtain an "open" format, which has a line break
  410. %       before each block and lines after the first are indented within blocks,
  411. %       by giving the optional \documentstyle argument `openbib';
  412. %       The default is the "closed" format---blocks runs together.
  413. %
  414. %   Citation alphabetic label format:
  415. %               [Knu73] for single author (or editor or key)
  416. %               [AHU83] (first letters of last names) for multiple authors
  417. %
  418. %   Citation label numberic format:
  419. %               [number]
  420. %
  421. %   Reference list ordering for sorted, alphabetic lables:
  422. %               alphabetical by citation label, then by author(s) or whatever
  423. %               passes for author in the absence of one, then by year,
  424. %               then title
  425. %
  426. %   Reference list ordering for sorted, numeric lables:
  427. %               alphabetical by author(s) or whatever passes
  428. %               for author in the absence of one, then by year, then title
  429. %
  430. %   Reference list ordering for unsorted:
  431. %               by the order cited in the text
  432. %
  433. %   History
  434. %   12/16/84    (HWT)   Original `plain' version, by Howard Trickey.
  435. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  436. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  437. %    2/17/85    (HWT)   Template file and other standard styles made.
  438. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  439. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  440. %                       fixed Theoretical Computer Science macro name;
  441. %                       fixed the format.vol.num.pages function.
  442. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  443. %                       assignment operator (:=) arguments reversed;
  444. %                       the preamble$ function outputs the database PREAMBLE;
  445. %                       entry.max$ and global.max$ (built-in) variables replace
  446. %                       entry.string.max and global.string.max functions;
  447. %                       alphabetizing by year then title, not just title;
  448. %                       many unnecessary ties removed; \it ==> \em;
  449. %                       the `alpha' style uses a superscripted `+' instead of a
  450. %                       `*' for unnamed names in constructing the label;
  451. %                       the `abbrv' style now uses "Mar." and "Sept.";
  452. %                       the functions calc.label and presort now look at just
  453. %                       the fields they're supposed to;
  454. %                       BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  455. %                       INBOOK and INCOLLECTION take an optional type (e.g.
  456. %                       type = "Section"), overriding the default "chapter";
  457. %                       BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  458. %                       either volume or number, not just volume;
  459. %                       INCOLLECTION now allows an edition and series field;
  460. %                       PROCEEDINGS and INPROCEEDINGS now use the address field
  461. %                       to tell where a conference was held;
  462. %                       INPROCEEDINGS and PROCEEDINGS now allow either volume
  463. %                       or number, and also a series field;
  464. %                       MASTERSTHESIS and PHDTHESIS accept types other than
  465. %                       "Master's thesis" and "PhD thesis";
  466. %                       UNPUBLISHED now outputs, in one block, note then date;
  467. %                       MANUAL now prints out the organization in
  468. %                       the first block if the author field is empty;
  469. %                       MISC can't be empty---it requires some optional field.
  470. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  471. %                       erroneous occurrences of `cite ' to `cite$ '; this
  472. %                       change didn't affect the four standard styles, so the
  473. %                       0.99a versions of those styles are still current.
  474. %
  475. % The ENTRY declaration
  476. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  477. %   but no fullauthor or editors fields because BibTeX does name handling.
  478. %   The annote field is commented out here because this family doesn't
  479. %   include an annotated bibliography style.  And in addition to the fields
  480. %   listed here, BibTeX has a built-in crossref field, explained later.
  481.  
  482. ENTRY
  483. % Fields:
  484.   { address
  485. %           Usually the address of a publisher or other type of organization.
  486. %           Put information in this field only if it helps the reader find the
  487. %           thing---for example you should omit the address of a major
  488. %           publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  489. %           however, it's the address of the conference; for those two entry
  490. %           types, include the publisher's or organization's address, if
  491. %           necessary, in the publisher or organization field.
  492. %    annote
  493. %           Long annotation---for annotated bibliographies (begins sentence).
  494.     author
  495. %           Name(s) of author(s), in BibTeX name format.
  496.     booktitle
  497. %           Book title when the thing being referenced isn't the whole book.
  498. %           For book entries, the title field should be used instead.
  499.     chapter
  500. %           Chapter (or section or whatever) number.
  501.     edition
  502. %           Edition of a book---should be an ordinal (e.g., "Second").
  503.     editor
  504. %           Name(s) of editor(s), in BibTeX name format.
  505. %           If there is also an author field, then the editor field should be
  506. %           for the book or collection that the work appears in.
  507.     howpublished
  508. %            How something strange has been published (begins sentence).
  509.     institution
  510. %           Sponsoring institution of a technical report.
  511.     journal
  512. %           Journal name (macros are provided for many).
  513.     key
  514. %           Alphabetizing, labeling, and cross-referencing key
  515. %           (needed when an entry has no author or editor).
  516. #if !NAMED_REFS
  517.     month
  518. #else NAMED_REFS
  519. %    month              not used in apalike
  520. #endif
  521. %           Month (macros are provided).
  522.     note
  523. %           To help the reader find a reference (begins sentence).
  524.     number
  525. %           Number of a journal or technical report, or of a work in a series.
  526.     organization
  527. %           Organization sponsoring a conference (or publishing a manual); if
  528. %           the editor (or author) is empty, and if the organization produces
  529. %           an awkward label or cross reference, you should put appropriately
  530. %           condensed organization information in the key field as well.
  531.     pages
  532. %           Page number or numbers (use `--' to separate a range, use `+'
  533. %           to indicate pages following that don't form a simple range).
  534.     publisher
  535. %           Publisher name.
  536.     school
  537. %           School name (for theses).
  538.     series
  539. %           The name of a series or set of books.
  540. %           An individual book will will also have it's own title.
  541.     title
  542. %           The title of the thing you're referred to.
  543.     type
  544. %           Type of a Techreport (e.g., "Research Note") to be used instead of
  545. %           the default "Technical Report"; or, similarly, the type of a
  546. %           thesis; or of a part of a book.
  547.     volume
  548. %           The volume number of a journal or multivolume work.
  549.     year
  550. %           The year should contain only numerals (technically, it should end
  551. %           with four numerals, after purification; doesn't a begin sentence).
  552.   }
  553. % There are no integer entry variables
  554.   {}
  555. % These string entry variables are used to form the citation label.
  556. % In a storage pinch, sort.label can be easily computed on the fly.
  557. #if LAB_ALPH
  558. #if SORTED
  559.   { label extra.label sort.label }
  560. #else !SORTED
  561. % It doesn't seem like a good idea to use an order-of-citation
  562. % reference list when using alphabetic labels, but when this happens
  563. % we do things a little differently
  564.   { label }
  565. #endif SORTED
  566. #else !LAB_ALPH
  567.   { label }
  568. #endif LAB_ALPH
  569.  
  570. % Each entry function starts by calling output.bibitem, to write the
  571. % \bibitem and its arguments to the .BBL file.  Then the various fields
  572. % are formatted and printed by output or output.check.  Those functions
  573. % handle the writing of separators (commas, periods, \newblock's),
  574. % taking care not to do so when they are passed a null string.
  575. % Finally, fin.entry is called to add the final period and finish the
  576. % entry.
  577. %
  578. % A bibliographic reference is formatted into a number of `blocks':
  579. % in the open format, a block begins on a new line and subsequent
  580. % lines of the block are indented.  A block may contain more than
  581. % one sentence (well, not a grammatical sentence, but something to
  582. % be ended with a sentence ending period).  The entry functions should
  583. % call new.block whenever a block other than the first is about to be
  584. % started.  They should call new.sentence whenever a new sentence is
  585. % to be started.  The output functions will ensure that if two
  586. % new.sentence's occur without any non-null string being output between
  587. % them then there won't be two periods output.  Similarly for two
  588. % successive new.block's.
  589. %
  590. % The output routines don't write their argument immediately.
  591. % Instead, by convention, that argument is saved on the stack to be
  592. % output next time (when we'll know what separator needs to come
  593. % after it).  Meanwhile, the output routine has to pop the pending
  594. % output off the stack, append any needed separator, and write it.
  595. %
  596. % To tell which separator is needed, we maintain an output.state.
  597. % It will be one of these values:
  598. %       before.all              just after the \bibitem
  599. %       mid.sentence            in the middle of a sentence: comma needed
  600. %                                       if more sentence is output
  601. %       after.sentence          just after a sentence: period needed
  602. %       after.block             just after a block (and sentence):
  603. %                                       period and \newblock needed.
  604. % Note: These styles don't use after.sentence
  605. %
  606. % VAR: output.state : INTEGER           -- state variable for output
  607. %
  608. % The output.nonnull function saves its argument (assumed to be nonnull)
  609. % on the stack, and writes the old saved value followed by any needed
  610. % separator.  The ordering of the tests is decreasing frequency of
  611. % occurrence.
  612. %
  613. % output.nonnull(s) ==
  614. %  BEGIN
  615. %       s := argument on stack
  616. %       if output.state = mid.sentence then
  617. %           write$(pop() * ", ")
  618. %                 -- "pop" isn't a function: just use stack top
  619. %       else
  620. %           if output.state = after.block then
  621. %               write$(add.period$(pop()))
  622. %               newline$
  623. %               write$("\newblock ")
  624. %           else
  625. %               if output.state = before.all then
  626. %                   write$(pop())
  627. %               else        -- output.state should be after.sentence
  628. %                   write$(add.period$(pop()) * " ")
  629. %               fi
  630. %           fi
  631. %           output.state := mid.sentence
  632. %       fi
  633. %       push s on stack
  634. %  END
  635. %
  636. % The output function calls output.nonnull if its argument is non-empty;
  637. % its argument may be a missing field (thus, not necessarily a string)
  638. %
  639. % output(s) ==
  640. %  BEGIN
  641. %       if not empty$(s) then output.nonnull(s)
  642. %       fi
  643. %  END
  644. %
  645. % The output.check function is the same as the output function except that, if
  646. % necessary, output.check warns the user that the t field shouldn't be empty
  647. % (this is because it probably won't be a good reference without the field;
  648. % the entry functions try to make the formatting look reasonable even when
  649. % such fields are empty).
  650. %
  651. % output.check(s,t) ==
  652. %  BEGIN
  653. %       if empty$(s) then
  654. %           warning$("empty " * t * " in " * cite$)
  655. %       else output.nonnull(s)
  656. %       fi
  657. %  END
  658. %
  659. % The output.bibitem function writes the \bibitem for the current entry
  660. % (the label should already have been set up), and sets up the separator
  661. % state for the output functions.  And, it leaves a string on the stack
  662. % as per the output convention.
  663. %
  664. % output.bibitem ==
  665. %  BEGIN
  666. %       newline$
  667. %       write$("\bibitem[")     % for alphabetic labels,
  668. %       write$(label)           % these three lines
  669. %       write$("]{")            % are used
  670. %       write$("\bibitem{")             % this line for numeric labels
  671. %       write$(cite$)
  672. %       write$("}")
  673. %       push "" on stack
  674. %       output.state := before.all
  675. %  END
  676. %
  677. % The fin.entry function finishes off an entry by adding a period to the
  678. % string remaining on the stack.  If the state is still before.all
  679. % then nothing was produced for this entry, so the result will look bad,
  680. % but the user deserves it. (We don't omit the whole entry because the
  681. % entry was cited, and a bibitem is needed to define the citation label.)
  682. %
  683. % fin.entry ==
  684. %  BEGIN
  685. %       write$(add.period$(pop()))
  686. %       newline$
  687. %  END
  688. %
  689. % The new.block function prepares for a new block to be output, and
  690. % new.sentence prepares for a new sentence.
  691. %
  692. % new.block ==
  693. %  BEGIN
  694. %       if output.state <> before.all then
  695. %           output.state := after.block
  696. %       fi
  697. %  END
  698. %
  699. % new.sentence ==
  700. %  BEGIN
  701. %       if output.state <> after.block then
  702. %           if output.state <> before.all then
  703. %               output.state :=  after.sentence
  704. %           fi
  705. %       fi
  706. %  END
  707. %
  708.  
  709. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  710.  
  711. FUNCTION {init.state.consts}
  712. { #0 'before.all :=
  713.   #1 'mid.sentence :=
  714.   #2 'after.sentence :=
  715.   #3 'after.block :=
  716. }
  717.  
  718. % the variables s and t are temporary string holders
  719.  
  720. STRINGS { s t }
  721.  
  722. FUNCTION {output.nonnull}
  723. { 's :=
  724.   output.state mid.sentence =
  725.     { ", " * write$ }
  726.     { output.state after.block =
  727. #if !COMMA_DELIMIT
  728.         { add.period$ write$
  729. #else COMMA_DELIMIT
  730.         { "," * write$
  731. #endif
  732.           newline$
  733.           "\newblock " write$
  734.         }
  735.         { output.state before.all =
  736.             'write$
  737.             { add.period$ " " * write$ }
  738.           if$
  739.         }
  740.       if$
  741.       mid.sentence 'output.state :=
  742.     }
  743.   if$
  744.   s
  745. }
  746.  
  747. FUNCTION {output}
  748. { duplicate$ empty$
  749.     'pop$
  750.     'output.nonnull
  751.   if$
  752. }
  753.  
  754. FUNCTION {output.check}
  755. { 't :=
  756.   duplicate$ empty$
  757.     { pop$ "empty " t * " in " * cite$ * warning$ }
  758.     'output.nonnull
  759.   if$
  760. }
  761.  
  762. #if NAMED_REFS
  763. %                                       apalike needs this function because
  764. %                                       the year has special punctuation;
  765. %                                       apalike ignores the month
  766. FUNCTION {output.year.check}
  767. { year empty$
  768.     { "empty year in " cite$ * warning$ }
  769.     { write$
  770.       " (" year * extra.label * ")" *
  771.       mid.sentence 'output.state :=
  772.     }
  773.   if$
  774. }
  775. #endif NAMED_REFS
  776.  
  777. FUNCTION {output.bibitem}
  778. { newline$
  779. #if LAB_ALPH
  780.   "\bibitem[" write$
  781.   label write$
  782.   "]{" write$
  783. #else
  784.   "\bibitem{" write$
  785. #endif LAB_ALPH
  786.   cite$ write$
  787.   "}" write$
  788.   newline$
  789.   ""
  790.   before.all 'output.state :=
  791. }
  792.  
  793. % This function finishes all entries.
  794.  
  795. FUNCTION {fin.entry}
  796. { add.period$
  797.   write$
  798.   newline$
  799. }
  800.  
  801. FUNCTION {new.block}
  802. { output.state before.all =
  803.     'skip$
  804.     { after.block 'output.state := }
  805.   if$
  806. }
  807.  
  808. FUNCTION {new.sentence}
  809. #if !COMMA_DELIMIT
  810. { output.state after.block =
  811.     'skip$
  812.     { output.state before.all =
  813.         'skip$
  814.         { after.sentence 'output.state := }
  815.       if$
  816.     }
  817.   if$
  818. #else COMMA_DELIMIT
  819. { skip$
  820. #endif
  821. }
  822.  
  823. % These three functions pop one or two (integer) arguments from the stack
  824. % and push a single one, either 0 or 1.
  825. % The 'skip$ in the `and' and `or' functions are used because
  826. % the corresponding if$ would be idempotent
  827.  
  828. FUNCTION {not}
  829. {   { #0 }
  830.     { #1 }
  831.   if$
  832. }
  833.  
  834. FUNCTION {and}
  835. {   'skip$
  836.     { pop$ #0 }
  837.   if$
  838. }
  839.  
  840. FUNCTION {or}
  841. {   { pop$ #1 }
  842.     'skip$
  843.   if$
  844. }
  845.  
  846. % Sometimes we begin a new block only if the block will be big enough.  The
  847. % new.block.checka function issues a new.block if its argument is nonempty;
  848. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  849.  
  850. #if !NAMED_REFS
  851. FUNCTION {new.block.checka}
  852. { empty$
  853.     'skip$
  854.     'new.block
  855.   if$
  856. }
  857. #endif !NAMED_REFS
  858.  
  859. FUNCTION {new.block.checkb}
  860. { empty$
  861.   swap$ empty$
  862.   and
  863.     'skip$
  864.     'new.block
  865.   if$
  866. }
  867.  
  868. #if !NAMED_REFS
  869. % The new.sentence.check functions are analogous.
  870.  
  871. FUNCTION {new.sentence.checka}
  872. { empty$
  873.     'skip$
  874.     'new.sentence
  875.   if$
  876. }
  877.  
  878. FUNCTION {new.sentence.checkb}
  879. { empty$
  880.   swap$ empty$
  881.   and
  882.     'skip$
  883.     'new.sentence
  884.   if$
  885. }
  886. #endif !NAMED_REFS
  887.  
  888. % Here are some functions for formatting chunks of an entry.
  889. % By convention they either produce a string that can be followed by
  890. % a comma or period (using add.period$, so it is OK to end in a period),
  891. % or they produce the null string.
  892. %
  893. % A useful utility is the field.or.null function, which checks if the
  894. % argument is the result of pushing a `missing' field (one for which no
  895. % assignment was made when the current entry was read in from the database)
  896. % or the result of pushing a string having no non-white-space characters.
  897. % It returns the null string if so, otherwise it returns the field string.
  898. % Its main (but not only) purpose is to guarantee that what's left on the
  899. % stack is a string rather than a missing field.
  900. %
  901. % field.or.null(s) ==
  902. %  BEGIN
  903. %       if empty$(s) then return ""
  904. %       else return s
  905. %  END
  906. %
  907. % Another helper function is emphasize, which returns the argument emphazised,
  908. % if that is non-empty, otherwise it returns the null string.  Italic
  909. % corrections aren't used, so this function should be used when punctation
  910. % will follow the result.
  911. %
  912. % emphasize(s) ==
  913. %  BEGIN
  914. %       if empty$(s) then return ""
  915. %       else return "{\em " * s * "}"
  916. %
  917. % The format.names function formats the argument (which should be in
  918. % BibTeX name format) into "First Von Last, Junior", separated by commas
  919. % and with an "and" before the last (but ending with "et~al." if the last
  920. % of multiple authors is "others").  This function's argument should always
  921. % contain at least one name.
  922. %
  923. % VAR: nameptr, namesleft, numnames: INTEGER
  924. % pseudoVAR: nameresult: STRING         (it's what's accumulated on the stack)
  925. %
  926. % format.names(s) ==
  927. %  BEGIN
  928. %       nameptr := 1
  929. %       numnames := num.names$(s)
  930. %       namesleft := numnames
  931. %       while namesleft > 0
  932. %         do
  933. %                               % for full names:
  934. %           t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  935. %                               % for abbreviated first names:
  936. %           t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  937. %           if nameptr > 1 then
  938. %               if namesleft > 1 then nameresult := nameresult * ", " * t
  939. %               else if numnames > 2
  940. %                      then nameresult := nameresult * ","
  941. %                    fi
  942. %                    if t = "others"
  943. %                      then nameresult := nameresult * " et~al."
  944. %                      else nameresult := nameresult * " and " * t
  945. %                    fi
  946. %               fi
  947. %           else nameresult := t
  948. %           fi
  949. %           nameptr := nameptr + 1
  950. %           namesleft := namesleft - 1
  951. %         od
  952. %       return nameresult
  953. %  END
  954. %
  955. % The format.authors function returns the result of format.names(author)
  956. % if the author is present, or else it returns the null string
  957. %
  958. % format.authors ==
  959. %  BEGIN
  960. %       if empty$(author) then return ""
  961. %       else return format.names(author)
  962. %       fi
  963. %  END
  964. %
  965. % Format.editors is like format.authors, but it uses the editor field,
  966. % and appends ", editor" or ", editors"
  967. %
  968. % format.editors ==
  969. %  BEGIN
  970. %       if empty$(editor) then return ""
  971. %       else
  972. %           if num.names$(editor) > 1 then
  973. %               return format.names(editor) * ", editors"
  974. %           else
  975. %               return format.names(editor) * ", editor"
  976. %           fi
  977. %       fi
  978. %  END
  979. %
  980. % Other formatting functions are similar, so no "comment version" will be
  981. % given for them.
  982. %
  983. % The `pop$' in this function gets rid of the duplicate `empty' value and
  984. % the `skip$' returns the duplicate field value
  985.  
  986. FUNCTION {field.or.null}
  987. { duplicate$ empty$
  988.     { pop$ "" }
  989.     'skip$
  990.   if$
  991. }
  992.  
  993. FUNCTION {emphasize}
  994. { duplicate$ empty$
  995.     { pop$ "" }
  996.     { "{\em " swap$ * "}" * }
  997.   if$
  998. }
  999.  
  1000. #if CSC_NAMES
  1001. FUNCTION {caps}
  1002. { duplicate$ empty$
  1003.     { pop$ "" }
  1004.     { "{\sc " swap$ * "}" * }
  1005.   if$
  1006. }
  1007. #endif
  1008.  
  1009. #if BOLD_VOL
  1010. FUNCTION {embolden}
  1011. { duplicate$ empty$
  1012.     { pop$ "" }
  1013.     { "{\bf " swap$ * "}" * }
  1014.   if$
  1015. }
  1016. #endif
  1017.  
  1018. #if BRACKET_NOTE
  1019. FUNCTION {bracket}
  1020. { duplicate$ empty$
  1021.     { pop$ "" }
  1022.     { "[" swap$ * "]" * }
  1023.   if$
  1024. }
  1025. #endif
  1026.  
  1027. #if PAREN_DATE
  1028. FUNCTION {paren}
  1029. { duplicate$ empty$
  1030.     { pop$ "" }
  1031.     { "(" swap$ * ")" * }
  1032.   if$
  1033. }
  1034. #endif
  1035.  
  1036. INTEGERS { nameptr namesleft numnames }
  1037.  
  1038. #if MAX_NAMES
  1039. INTEGERS { etal }
  1040. #endif
  1041.  
  1042. FUNCTION {format.names}
  1043. { 's :=
  1044.   #1 'nameptr :=
  1045.   s num.names$ 'numnames :=
  1046. #if !MAX_NAMES
  1047.   numnames 'namesleft :=
  1048. #else MAX_NAMES
  1049.   numnames #MAX_NAMES >
  1050.   s numnames "{ll}" format.name$ "others" = numnames #MIN_NAMES > and
  1051.   or 'etal :=
  1052.   etal
  1053.     { #MIN_NAMES #1 + 'namesleft := }
  1054.     { numnames 'namesleft := }
  1055.   if$
  1056. #endif
  1057.     { namesleft #0 > }
  1058. #if NAME_FULL
  1059. #if !NAME_INVERT
  1060.     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
  1061. #else NAME_INVERT
  1062.     { s nameptr "{vv~}{ll}{, jj}{, ff}" format.name$ 't :=
  1063. #endif
  1064. #else
  1065. #if !NAME_INVERT
  1066.     { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  1067. #else NAME_INVERT
  1068.     { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
  1069. #endif
  1070. #endif NAME_FULL
  1071. #if NAME_UPPER
  1072.       t "others" =
  1073.         'skip$
  1074.         { t "u" change.case$ 't := }
  1075.       if$
  1076. #endif
  1077. #if CSC_NAMES
  1078.       t "others" =
  1079.         'skip$
  1080.         { t caps 't := }
  1081.       if$
  1082. #endif
  1083.       nameptr #1 >
  1084.         { namesleft #1 >
  1085.             { ", " * t * }
  1086. #if !MAX_NAMES
  1087.             { numnames #2 >
  1088.                 { "," * }
  1089.                 'skip$
  1090.               if$
  1091.               t "others" =
  1092. #if !ETAL_EMPH
  1093.                 { " et~al." * }
  1094. #else ETAL_EMPH
  1095.                 { " {\em et~al.}" * }
  1096. #endif ETAL_EMPH
  1097.                 { " and " * t * }
  1098.               if$
  1099.             }
  1100. #else MAX_NAMES
  1101.             { nameptr #2 >
  1102.                 { "," * }
  1103.                 'skip$
  1104.               if$
  1105.               t "others" =
  1106.               etal or
  1107. #if !ETAL_EMPH
  1108.                 { " et~al." * }
  1109. #else ETAL_EMPH
  1110.                 { " {\em et~al.}" * }
  1111. #endif ETAL_EMPH
  1112.                 { " and " * t * }
  1113.               if$
  1114.             }
  1115. #endif
  1116.           if$
  1117.         }
  1118.         't
  1119.       if$
  1120.       nameptr #1 + 'nameptr :=
  1121.       namesleft #1 - 'namesleft :=
  1122.     }
  1123.   while$
  1124. }
  1125.  
  1126. FUNCTION {format.authors}
  1127. { author empty$
  1128.     { "" }
  1129.     { author format.names }
  1130.   if$
  1131. }
  1132.  
  1133. #if NAMED_REFS
  1134. FUNCTION {format.key}                   % this function is just for apalike
  1135. { empty$
  1136.     { key field.or.null }
  1137.     { "" }
  1138.   if$
  1139. }
  1140. #endif NAMED_REFS
  1141.  
  1142. FUNCTION {format.editors}
  1143. { editor empty$
  1144.     { "" }
  1145.     { editor format.names
  1146.       editor num.names$ #1 >
  1147.         { ", editors" * }
  1148.         { ", editor" * }
  1149.       if$
  1150.     }
  1151.   if$
  1152. }
  1153.  
  1154. #if EDIT_VAR
  1155. FUNCTION {format.edited}
  1156. { editor empty$
  1157.     { "" }
  1158.     { "edited by " editor format.names * }
  1159.   if$
  1160. }
  1161. #endif
  1162.  
  1163. % The format.title function is used for non-book-like titles.
  1164. % For most styles we convert to lowercase (except for the very first letter,
  1165. % and except for the first one after a colon (followed by whitespace)),
  1166. % and hope the user has brace-surrounded words that need to stay capitilized;
  1167. % for some styles, however, we leave it as it is in the database.
  1168.  
  1169. FUNCTION {format.title}
  1170. { title empty$
  1171.     { "" }
  1172. #if ATIT_LOWER
  1173.     { title "t" change.case$ }
  1174. #else
  1175.     'title
  1176. #endif ATIT_LOWER
  1177.   if$
  1178. }
  1179.  
  1180. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  1181. % constant glob_str_size, the maximum length of a global string variable.
  1182. % Analogously, BibTeX sets the global integer variable entry.max$ to
  1183. % ent_str_size, the maximum length of an entry string variable.
  1184. % The style designer may change these if necessary (but this is unlikely)
  1185.  
  1186. % The n.dashify function makes each single `-' in a string a double `--'
  1187. % if it's not already
  1188. %
  1189. % pseudoVAR: pageresult: STRING         (it's what's accumulated on the stack)
  1190. %
  1191. % n.dashify(s) ==
  1192. %  BEGIN
  1193. %       t := s
  1194. %       pageresult := ""
  1195. %       while (not empty$(t))
  1196. %         do
  1197. %           if (first character of t = "-")
  1198. %             then
  1199. %               if (next character isn't)
  1200. %                 then
  1201. %                   pageresult := pageresult * "--"
  1202. %                   t := t with the "-" removed
  1203. %                 else
  1204. %                   while (first character of t = "-")
  1205. %                     do
  1206. %                       pageresult := pageresult * "-"
  1207. %                       t := t with the "-" removed
  1208. %                     od
  1209. %               fi
  1210. %             else
  1211. %               pageresult := pageresult * the first character
  1212. %               t := t with the first character removed
  1213. %           fi
  1214. %         od
  1215. %       return pageresult
  1216. %  END
  1217.  
  1218. FUNCTION {n.dashify}
  1219. { 't :=
  1220.   ""
  1221.     { t empty$ not }
  1222.     { t #1 #1 substring$ "-" =
  1223.         { t #1 #2 substring$ "--" = not
  1224.             { "--" *
  1225.               t #2 global.max$ substring$ 't :=
  1226.             }
  1227.             {   { t #1 #1 substring$ "-" = }
  1228.                 { "-" *
  1229.                   t #2 global.max$ substring$ 't :=
  1230.                 }
  1231.               while$
  1232.             }
  1233.           if$
  1234.         }
  1235.         { t #1 #1 substring$ *
  1236.           t #2 global.max$ substring$ 't :=
  1237.         }
  1238.       if$
  1239.     }
  1240.   while$
  1241. }
  1242.  
  1243. #define TEMP 0
  1244. #if PAGE_START_J
  1245. #define TEMP 1
  1246. #endif
  1247. #if PAGE_START_O
  1248. #define TEMP 1
  1249. #endif
  1250.  
  1251. #if TEMP
  1252. FUNCTION {first.page}
  1253. { 't :=
  1254.   ""
  1255.     {  t empty$ not t #1 #1 substring$ "-" = not and }
  1256.     { t #1 #1 substring$ *
  1257.       t #2 global.max$ substring$ 't :=
  1258.     }
  1259.   while$
  1260. }
  1261. #endif
  1262.  
  1263. #if !NAMED_REFS
  1264. % The format.date function is for the month and year, but we give a warning if
  1265. % there's an empty year but the month is there, and we return the empty string
  1266. % if they're both empty.
  1267.  
  1268. FUNCTION {format.date}
  1269. { year empty$
  1270. #if !MONTH_SUPPRESS
  1271.     { month empty$
  1272.         { "" }
  1273.         { "there's a month but no year in " cite$ * warning$
  1274.           month
  1275.         }
  1276.       if$
  1277.     }
  1278.     { month empty$
  1279.         'year
  1280.         { month " " * year * }
  1281.       if$
  1282.     }
  1283. #else MONTH_SUPPRESS
  1284.     { "" }
  1285.     'year
  1286. #endif
  1287.   if$
  1288. }
  1289. #endif !NAMED_REFS
  1290.  
  1291. % The format.btitle is for formatting the title field when it is a book-like
  1292. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  1293.  
  1294. FUNCTION {format.btitle}
  1295. { title emphasize
  1296. }
  1297.  
  1298. % For several functions we'll need to connect two strings with a
  1299. % tie (~) if the second one isn't very long (fewer than 3 characters).
  1300. % The tie.or.space.connect function does that.  It concatenates the two
  1301. % strings on top of the stack, along with either a tie or space between
  1302. % them, and puts this concatenation back onto the stack:
  1303. %
  1304. % tie.or.space.connect(str1,str2) ==
  1305. %    BEGIN
  1306. %       if text.length$(str2) < 3
  1307. %         then return the concatenation of str1, "~", and str2
  1308. %         else return the concatenation of str1, " ", and str2
  1309. %    END
  1310.  
  1311. FUNCTION {tie.or.space.connect}
  1312. { duplicate$ text.length$ #3 <
  1313.     { "~" }
  1314.     { " " }
  1315.   if$
  1316.   swap$ * *
  1317. }
  1318.  
  1319. % The either.or.check function complains if both fields or an either-or pair
  1320. % are nonempty.
  1321. %
  1322. % either.or.check(t,s) ==
  1323. %  BEGIN
  1324. %       if empty$(s) then
  1325. %           warning$(can't use both " * t * " fields in " * cite$)
  1326. %       fi
  1327. %  END
  1328.  
  1329. FUNCTION {either.or.check}
  1330. { empty$
  1331.     'pop$
  1332.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  1333.   if$
  1334. }
  1335.  
  1336. % The format.bvolume function is for formatting the volume and perhaps
  1337. % series name of a multivolume work.  If both a volume and a series field
  1338. % are there, we assume the series field is the title of the whole multivolume
  1339. % work (the title field should be the title of the thing being referred to),
  1340. % and we add an "of <series>".  This function is called in mid-sentence.
  1341.  
  1342. FUNCTION {format.bvolume}
  1343. { volume empty$
  1344.     { "" }
  1345.     { "volume" volume tie.or.space.connect
  1346.       series empty$
  1347.         'skip$
  1348.         { " of " * series emphasize * }
  1349.       if$
  1350.       "volume and number" number either.or.check
  1351.     }
  1352.   if$
  1353. }
  1354.  
  1355. % The format.number.series function is for formatting the series name
  1356. % and perhaps number of a work in a series.  This function is similar to
  1357. % format.bvolume, although for this one the series must exist (and the
  1358. % volume must not exist).  If the number field is empty we output either
  1359. % the series field unchanged if it exists or else the null string.
  1360. % If both the number and series fields are there we assume the series field
  1361. % gives the name of the whole series (the title field should be the title
  1362. % of the work being one referred to), and we add an "in <series>".
  1363. % We capitilize Number when this function is used at the beginning of a block.
  1364.  
  1365. FUNCTION {format.number.series}
  1366. { volume empty$
  1367.     { number empty$
  1368.         { series field.or.null }
  1369.         { output.state mid.sentence =
  1370.             { "number" }
  1371.             { "Number" }
  1372.           if$
  1373.           number tie.or.space.connect
  1374.           series empty$
  1375.             { "there's a number but no series in " cite$ * warning$ }
  1376.             { " in " * series * }
  1377.           if$
  1378.         }
  1379.       if$
  1380.     }
  1381.     { "" }
  1382.   if$
  1383. }
  1384.  
  1385. % The format.edition function appends " edition" to the edition, if present.
  1386. % We lowercase the edition (it should be something like "Third"), because
  1387. % this doesn't start a sentence.
  1388.  
  1389. FUNCTION {format.edition}
  1390. { edition empty$
  1391.     { "" }
  1392.     { output.state mid.sentence =
  1393.         { edition "l" change.case$ " edition" * }
  1394.         { edition "t" change.case$ " edition" * }
  1395.       if$
  1396.     }
  1397.   if$
  1398. }
  1399.  
  1400. % The format.pages function is used for formatting a page range in a book
  1401. % (and in rare circumstances, an article).
  1402. %
  1403. % The multi.page.check function examines the page field for a "-" or "," or "+"
  1404. % so that format.pages can use "page" instead of "pages" if none exists.
  1405. % Note: global.max$ here means "take the rest of the string"
  1406. %
  1407. % VAR: multiresult: INTEGER     (actually, a boolean)
  1408. %
  1409. % multi.page.check(s) ==
  1410. %  BEGIN
  1411. %       t := s
  1412. %       multiresult := false
  1413. %       while ((not multiresult) and (not empty$(t)))
  1414. %         do
  1415. %           if (first character of t = "-" or "," or "+")
  1416. %             then multiresult := true
  1417. %             else t := t with the first character removed
  1418. %           fi
  1419. %         od
  1420. %       return multiresult
  1421. %  END
  1422.  
  1423. INTEGERS { multiresult }
  1424.  
  1425. FUNCTION {multi.page.check}
  1426. { 't :=
  1427.   #0 'multiresult :=
  1428.     { multiresult not
  1429.       t empty$ not
  1430.       and
  1431.     }
  1432.     { t #1 #1 substring$
  1433.       duplicate$ "-" =
  1434.       swap$ duplicate$ "," =
  1435.       swap$ "+" =
  1436.       or or
  1437.         { #1 'multiresult := }
  1438.         { t #2 global.max$ substring$ 't := }
  1439.       if$
  1440.     }
  1441.   while$
  1442.   multiresult
  1443. }
  1444.  
  1445. % This function doesn't begin a sentence so "pages" isn't capitalized.
  1446. % Other functions that use this should keep that in mind.
  1447.  
  1448. FUNCTION {format.pages}
  1449. { pages empty$
  1450.     { "" }
  1451.     { pages multi.page.check
  1452. #if !PAGE_ABBREV
  1453.         { "pages" pages n.dashify tie.or.space.connect }
  1454.         { "page" pages tie.or.space.connect }
  1455. #else PAGE_ABBREV
  1456.         { "pp." pages n.dashify tie.or.space.connect }
  1457.         { "p." pages tie.or.space.connect }
  1458. #endif
  1459.       if$
  1460.     }
  1461.   if$
  1462. }
  1463.  
  1464. #if TEMP
  1465. FUNCTION {format.pages.a}
  1466. { pages empty$
  1467.     { "" }
  1468. #if !PAGE_ABBREV
  1469.     { "page" pages first.page tie.or.space.connect }
  1470. #else PAGE_ABBREV
  1471.     { "p." pages first.page tie.or.space.connect }
  1472. #endif
  1473.   if$
  1474. }
  1475. #endif
  1476.  
  1477. % The format.vol.num.pages function is for the volume, number, and page range
  1478. % of a journal article.  We use the format:  vol(number):pages, with some
  1479. % variations for empty fields.  This doesn't begin a sentence.
  1480.  
  1481. FUNCTION {format.vol.num.pages}
  1482. #if !BOLD_VOL
  1483. { volume field.or.null
  1484. #else BOLD_VOL
  1485. { volume field.or.null embolden
  1486. #endif
  1487. #if VOLUME_SPACE
  1488.   " " swap$ * *
  1489. #endif
  1490. #if !NUM_SUPPRESS
  1491.   number empty$
  1492.     'skip$
  1493.     { "(" number * ")" * *
  1494.       volume empty$
  1495.         { "there's a number but no volume in " cite$ * warning$ }
  1496.         'skip$
  1497.       if$
  1498.     }
  1499.   if$
  1500. #endif
  1501. #if DATE_FIRST
  1502.   format.date empty$
  1503.     'skip$
  1504.     { duplicate$ empty$
  1505.         { pop$ format.date paren }
  1506.         { " " * format.date paren * }
  1507.       if$
  1508.     }
  1509.   if$
  1510. #endif
  1511.   pages empty$
  1512.     'skip$
  1513.     { duplicate$ empty$
  1514. #if !PAGE_START_J
  1515.         { pop$ format.pages }
  1516. #else PAGE_START_J
  1517.         { pop$ format.pages.a }
  1518. #endif
  1519. #if !PAGE_START_J
  1520. #if !DATE_FIRST
  1521. #if !VOLUME_SPACE
  1522.         { ":" * pages n.dashify * }
  1523. #else VOLUME_SPACE
  1524.         { ", " * pages n.dashify * }
  1525. #endif
  1526. #else DATE_FIRST
  1527.         { " " * pages n.dashify *}
  1528. #endif
  1529. #else PAGE_START_J
  1530. #if !DATE_FIRST
  1531. #if !VOLUME_SPACE
  1532.         { ":" * pages first.page * }
  1533. #else VOLUME_SPACE
  1534.         { ", " * pages first.page * }
  1535. #endif
  1536. #else DATE_FIRST
  1537.         { " " * pages first.page *}
  1538. #endif
  1539. #endif
  1540.       if$
  1541.     }
  1542.   if$
  1543. }
  1544.  
  1545.  
  1546. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  1547. % type field (or else "chapter" if type is empty) in front of a chapter number.
  1548. % It then appends the pages, if present.  This doesn't begin a sentence.
  1549.  
  1550. FUNCTION {format.chapter.pages}
  1551. { chapter empty$
  1552.     'format.pages
  1553.     { type empty$
  1554.         { "chapter" }
  1555.         { type "l" change.case$ }
  1556.       if$
  1557.       chapter tie.or.space.connect
  1558.       pages empty$
  1559.         'skip$
  1560.         { ", " * format.pages * }
  1561.       if$
  1562.     }
  1563.   if$
  1564. }
  1565.  
  1566. % The format.in.ed.booktitle function is used for starting out a sentence
  1567. % that begins "In <booktitle>", putting an editor before the title if one
  1568. % exists.
  1569.  
  1570. FUNCTION {format.in.ed.booktitle}
  1571. { booktitle empty$
  1572.     { "" }
  1573.     { editor empty$
  1574. #if !COMMA_DELIMIT
  1575.         { "In " booktitle emphasize * }
  1576. #if !EDIT_VAR
  1577.         { "In " format.editors * ", " * booktitle emphasize * }
  1578. #else EDIT_VAR
  1579.         { "In " booktitle emphasize * ", " * format.edited * }
  1580. #endif
  1581. #else COMMA_DELIMIT
  1582.         { "in " booktitle emphasize * }
  1583. #if !EDIT_VAR
  1584.         { "in " format.editors * ", " * booktitle emphasize * }
  1585. #else EDIT_VAR
  1586.         { "in " booktitle emphasize * ", " * format.edited * }
  1587. #endif
  1588. #endif
  1589.       if$
  1590.     }
  1591.   if$
  1592. }
  1593.  
  1594. #if !NAMED_REFS
  1595. % The function empty.misc.check complains if all six fields are empty, and
  1596. % if there's been no sorting or alphabetic-label complaint.
  1597.  
  1598. FUNCTION {empty.misc.check}
  1599. { author empty$ title empty$ howpublished empty$
  1600.   month empty$ year empty$ note empty$
  1601.   and and and and and
  1602. #if SORTED
  1603.   key empty$ not and
  1604. #else !SORTED
  1605. #if LAB_ALPH
  1606.   key empty$ not and
  1607. #endif LAB_ALPH
  1608. #endif SORTED
  1609.     { "all relevant fields are empty in " cite$ * warning$ }
  1610.     'skip$
  1611.   if$
  1612. }
  1613. #endif
  1614.  
  1615. % The function format.thesis.type returns either the (case-changed) type field,
  1616. % if it is defined, or else the default string already on the stack
  1617. % (like "Master's thesis" or "PhD thesis").
  1618.  
  1619. FUNCTION {format.thesis.type}
  1620. { type empty$
  1621.     'skip$
  1622.     { pop$
  1623.       type "t" change.case$
  1624.     }
  1625.   if$
  1626. }
  1627.  
  1628. % The function format.tr.number makes a string starting with "Technical Report"
  1629. % (or type, if that field is defined), followed by the number if there is one;
  1630. % it returns the starting part (with a case change) even if there is no number.
  1631. % This is used at the beginning of a sentence.
  1632.  
  1633. FUNCTION {format.tr.number}
  1634. { type empty$
  1635.     { "Technical Report" }
  1636.     'type
  1637.   if$
  1638.   number empty$
  1639.     { "t" change.case$ }
  1640.     { number tie.or.space.connect }
  1641.   if$
  1642. }
  1643.  
  1644. % Now come the cross-referencing functions (these are invoked because
  1645. % one entry in the database file(s) cross-references another, by giving
  1646. % the other entry's database key in a `crossref' field).  This feature
  1647. % allows one or more titled things that are part of a larger titled
  1648. % thing to cross-reference the larger thing.  These styles allow for
  1649. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1650. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1651. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1652. % Each of these is explained in more detail later.
  1653. %
  1654. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1655. % intended for when an entire journal is devoted to a single topic---
  1656. % but since there is no JOURNAL entry type, the journal, too, should be
  1657. % classified as an ARTICLE but without the author and title fields).
  1658. % This will result in two warning messages for the journal's entry
  1659. % if it's included in the reference list, but such is life.
  1660. %
  1661. % format.article.crossref ==
  1662. %  BEGIN
  1663. %       if empty$(key) then
  1664. %           if empty$(journal) then
  1665. %               warning$("need key or journal for " * cite$ *
  1666. %                                               " to crossref " * crossref)
  1667. %               return(" \cite{" * crossref * "}")
  1668. %           else
  1669. %               return("In " * emphazise.correct (journal) *
  1670. %                                               " \cite{" * crossref * "}")
  1671. %               fi
  1672. %       else
  1673. %           return("In " * key * " \cite{" * crossref * "}")
  1674. %       fi
  1675. %  END
  1676. %
  1677. % The other cross-referencing functions are similar, so no "comment version"
  1678. % will be given for them.
  1679.  
  1680. #if !NAMED_REFS
  1681. FUNCTION {format.article.crossref}
  1682. { key empty$
  1683.     { journal empty$
  1684.         { "need key or journal for " cite$ * " to crossref " * crossref *
  1685.           warning$
  1686.           ""
  1687.         }
  1688. #if !JOUR_DEEMPH
  1689.         { "In {\em " journal * "\/}" * }
  1690. #else JOUR_DEEMPH
  1691.         { "In " journal * }
  1692. #endif
  1693.       if$
  1694.     }
  1695.     { "In " key * }
  1696.   if$
  1697.   " \cite{" * crossref * "}" *
  1698. }
  1699. #else NAMED_REFS
  1700. FUNCTION {format.article.crossref}
  1701. { "In"                                                  % this is for apalike
  1702.   " \cite{" * crossref * "}" *
  1703. }
  1704. #endif NAMED_REFS
  1705.  
  1706. #if !NAMED_REFS
  1707. % We use just the last names of editors for a cross reference: either
  1708. % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
  1709. % whether there are one, or two, or more than two editors.
  1710.  
  1711. FUNCTION {format.crossref.editor}
  1712. #if !CSC_NAMES
  1713. { editor #1 "{vv~}{ll}" format.name$
  1714. #else CSC_NAMES
  1715. { editor #1 "{vv~}{ll}" format.name$ caps
  1716. #endif
  1717.   editor num.names$ duplicate$
  1718.   #2 >
  1719. #if !ETAL_EMPH
  1720.     { pop$ " et~al." * }
  1721. #else ETAL_EMPH
  1722.     { pop$ " {\em et~al.}" * }
  1723. #endif ETAL_EMPH
  1724.     { #2 <
  1725.         'skip$
  1726.         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1727. #if !ETAL_EMPH
  1728.             { " et~al." * }
  1729. #else ETAL_EMPH
  1730.             { " {\em et~al.}" * }
  1731. #endif ETAL_EMPH
  1732. #if !CSC_NAMES
  1733.             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1734. #else CSC_NAMES
  1735.             { " and " * editor #2 "{vv~}{ll}" format.name$ caps * }
  1736. #endif
  1737.           if$
  1738.         }
  1739.       if$
  1740.     }
  1741.   if$
  1742. }
  1743. #endif
  1744.  
  1745. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1746. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1747. % Usually there will be an editor, in which case we use that to construct the
  1748. % cross reference; otherwise we use a nonempty key field or else the series
  1749. % field (since the series gives the title of the multivolume work).
  1750.  
  1751. FUNCTION {format.book.crossref}
  1752. { volume empty$
  1753.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1754.       "In "
  1755.     }
  1756.     { "Volume" volume tie.or.space.connect
  1757.       " of " *
  1758.     }
  1759.   if$
  1760. #if !NAMED_REFS
  1761.   editor empty$
  1762.   editor field.or.null author field.or.null =
  1763.   or
  1764.     { key empty$
  1765.         { series empty$
  1766.             { "need editor, key, or series for " cite$ * " to crossref " *
  1767.               crossref * warning$
  1768.               "" *
  1769.             }
  1770.             { "{\em " * series * "\/}" * }
  1771.           if$
  1772.         }
  1773.         { key * }
  1774.       if$
  1775.     }
  1776.     { format.crossref.editor * }
  1777.   if$
  1778.   " \cite{" * crossref * "}" *
  1779. #else NAMED_REFS
  1780.   "\cite{" * crossref * "}" *                           % this is for apalike
  1781. #endif
  1782. }
  1783.  
  1784. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1785. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1786. % Often there will be an editor, in which case we use that to construct
  1787. % the cross reference; otherwise we use a nonempty key field or else
  1788. % the booktitle field (which gives the cross-referenced work's title).
  1789.  
  1790. #if !NAMED_REFS
  1791. FUNCTION {format.incoll.inproc.crossref}
  1792. { editor empty$
  1793.   editor field.or.null author field.or.null =
  1794.   or
  1795.     { key empty$
  1796.         { booktitle empty$
  1797.             { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1798.               crossref * warning$
  1799.               ""
  1800.             }
  1801.             { "In {\em " booktitle * "\/}" * }
  1802.           if$
  1803.         }
  1804.         { "In " key * }
  1805.       if$
  1806.     }
  1807.     { "In " format.crossref.editor * }
  1808.   if$
  1809.   " \cite{" * crossref * "}" *
  1810. }
  1811. #else NAMED_REFS
  1812. FUNCTION {format.incoll.inproc.crossref}
  1813. { "In"                                                  % this is for apalike
  1814.   " \cite{" * crossref * "}" *
  1815. }
  1816. #endif NAMED_REFS
  1817.  
  1818. % Now we define the type functions for all entry types that may appear
  1819. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1820. % are the routines that actually generate the .BBL-file output for
  1821. % the entry.  These must all precede the READ command.  In addition, the
  1822. % style designer should have a function `default.type' for unknown types.
  1823. % Note: The fields (within each list) are listed in order of appearance,
  1824. % except as described for an `inbook' or a `proceedings'.
  1825. %
  1826. % The article function is for an article in a journal.  An article may
  1827. % CROSSREF another article.
  1828. %       Required fields: author, title, journal, year
  1829. %       Optional fields: volume, number, pages, month, note
  1830. %
  1831. % article ==
  1832. %  BEGIN
  1833. %       output.bibitem
  1834. %       output.check(format.authors,"author")
  1835. %       new.block
  1836. %       output.check(format.title,"title")
  1837. %       new.block
  1838. %       if missing$(crossref) then
  1839. %           output.check(emphasize(journal),"journal")
  1840. %           output(format.vol.num.pages)
  1841. %           output.check(format.date,"year")
  1842. %       else
  1843. %           output.nonnull(format.article.crossref)
  1844. %           output(format.pages)
  1845. %       fi
  1846. %       new.block
  1847. %       output(note)
  1848. %       fin.entry
  1849. %  END
  1850. %
  1851. % The book function is for a whole book.  A book may CROSSREF another book.
  1852. %       Required fields: author or editor, title, publisher, year
  1853. %       Optional fields: volume or number, series, address, edition, month,
  1854. %                       note
  1855. %
  1856. % book ==
  1857. %  BEGIN
  1858. %       if empty$(author) then output.check(format.editors,"author and editor")
  1859. %       else    output.check(format.authors,"author")
  1860. %               if missing$(crossref) then
  1861. %                   either.or.check("author and editor",editor)
  1862. %               fi
  1863. %       fi
  1864. %       new.block
  1865. %       output.check(format.btitle,"title")
  1866. %       if missing$(crossref) then
  1867. %           output(format.bvolume)
  1868. %           new.block
  1869. %           output(format.number.series)
  1870. %           new.sentence
  1871. %           output.check(publisher,"publisher")
  1872. %           output(address)
  1873. %       else
  1874. %           new.block
  1875. %           output.nonnull(format.book.crossref)
  1876. %       fi
  1877. %       output(format.edition)
  1878. %       output.check(format.date,"year")
  1879. %       new.block
  1880. %       output(note)
  1881. %       fin.entry
  1882. %  END
  1883. %
  1884. % The other entry functions are all quite similar, so no "comment version"
  1885. % will be given for them.
  1886.  
  1887. FUNCTION {article}
  1888. { output.bibitem
  1889.   format.authors "author" output.check
  1890. #if NAMED_REFS
  1891.   author format.key output                              % special for
  1892.   output.year.check                                     % apalike
  1893. #endif NAMED_REFS
  1894. #if !ATIT_SUPPRESS
  1895.   new.block
  1896.   format.title "title" output.check
  1897. #endif
  1898.   new.block
  1899.   crossref missing$
  1900. #if !VOLUME_SPACE
  1901. #if !JOUR_DEEMPH
  1902.     { journal emphasize "journal" output.check
  1903. #else JOUR_DEEMPH
  1904.     { journal "journal" output.check
  1905. #endif
  1906. #else VOLUME_SPACE
  1907. #if !JOUR_DEEMPH
  1908.     { journal emphasize
  1909. #else JOUR_DEEMPH
  1910.     { journal field.or.null
  1911. #endif
  1912. #endif
  1913. #if !NAMED_REFS
  1914. #if !DATE_FIRST
  1915. #if !PAREN_DATE
  1916.       format.vol.num.pages output
  1917.       format.date "year" output.check
  1918. #else PAREN_DATE
  1919.       format.vol.num.pages 
  1920.       format.date empty$
  1921.         'skip$
  1922.         { duplicate$ empty$
  1923.             { pop$ format.date paren }
  1924.             { " " * format.date paren * }
  1925.           if$
  1926.         }
  1927.       if$
  1928.       output
  1929. #endif
  1930. #else DATE_FIRST
  1931.       format.vol.num.pages output
  1932. #endif DATE_FIRST
  1933. #else NAMED_REFS
  1934.       format.vol.num.pages output
  1935. #endif NAMED_REFS
  1936.     }
  1937.     { format.article.crossref output.nonnull
  1938.       format.pages output
  1939.     }
  1940.   if$
  1941.   new.block
  1942.   note output
  1943.   fin.entry
  1944. }
  1945.  
  1946. FUNCTION {book}
  1947. { output.bibitem
  1948.   author empty$
  1949. #if !NAMED_REFS
  1950.     { format.editors "author and editor" output.check }
  1951. #else NAMED_REFS
  1952.     { format.editors "author and editor" output.check
  1953.       editor format.key output
  1954.     }
  1955. #endif NAMED_REFS
  1956.     { format.authors output.nonnull
  1957.       crossref missing$
  1958.         { "author and editor" editor either.or.check }
  1959.         'skip$
  1960.       if$
  1961.     }
  1962.   if$
  1963. #if NAMED_REFS
  1964.   output.year.check                             % special for apalike
  1965. #endif
  1966.   new.block
  1967.   format.btitle "title" output.check
  1968.   crossref missing$
  1969.     { format.bvolume output
  1970.       new.block
  1971.       format.number.series output
  1972.       new.sentence
  1973.       publisher "publisher" output.check
  1974.       address output
  1975.     }
  1976.     { new.block
  1977.       format.book.crossref output.nonnull
  1978.     }
  1979.   if$
  1980.   format.edition output
  1981. #if !NAMED_REFS
  1982.   format.date "year" output.check
  1983. #endif
  1984.   new.block
  1985.   note output
  1986.   fin.entry
  1987. }
  1988.  
  1989. % A booklet is a bound thing without a publisher or sponsoring institution.
  1990. %       Required: title
  1991. %       Optional: author, howpublished, address, month, year, note
  1992.  
  1993. FUNCTION {booklet}
  1994. { output.bibitem
  1995.   format.authors output
  1996. #if !NAMED_REFS
  1997.   new.block
  1998.   format.title "title" output.check
  1999.   howpublished address new.block.checkb
  2000.   howpublished output
  2001.   address output
  2002.   format.date output
  2003. #else NAMED_REFS
  2004.   author format.key output                              % special for
  2005.   output.year.check                                     % apalike
  2006.   new.block
  2007.   format.title "title" output.check
  2008.   new.block
  2009.   howpublished output
  2010.   address output
  2011. #endif NAMED_REFS
  2012.   new.block
  2013.   note output
  2014.   fin.entry
  2015. }
  2016.  
  2017. % For the conference entry type, see inproceedings.
  2018.  
  2019. % An inbook is a piece of a book: either a chapter and/or a page range.
  2020. % It may CROSSREF a book.  If there's no volume field, the type field
  2021. % will come before number and series.
  2022. %       Required: author or editor, title, chapter and/or pages, publisher,year
  2023. %       Optional: volume or number, series, type, address, edition, month, note
  2024.  
  2025. FUNCTION {inbook}
  2026. { output.bibitem
  2027.   author empty$
  2028. #if !NAMED_REFS
  2029.     { format.editors "author and editor" output.check }
  2030. #else NAMED_REFS
  2031.     { format.editors "author and editor" output.check
  2032.       editor format.key output
  2033.     }
  2034. #endif
  2035.     { format.authors output.nonnull
  2036.       crossref missing$
  2037.         { "author and editor" editor either.or.check }
  2038.         'skip$
  2039.       if$
  2040.     }
  2041.   if$
  2042. #if NAMED_REFS
  2043.   output.year.check                             % special for apalike
  2044. #endif
  2045.   new.block
  2046.   format.btitle "title" output.check
  2047.   crossref missing$
  2048.     { format.bvolume output
  2049.       format.chapter.pages "chapter and pages" output.check
  2050.       new.block
  2051.       format.number.series output
  2052.       new.sentence
  2053.       publisher "publisher" output.check
  2054.       address output
  2055.     }
  2056.     { format.chapter.pages "chapter and pages" output.check
  2057.       new.block
  2058.       format.book.crossref output.nonnull
  2059.     }
  2060.   if$
  2061.   format.edition output
  2062. #if !NAMED_REFS
  2063.   format.date "year" output.check
  2064. #endif
  2065.   new.block
  2066.   note output
  2067.   fin.entry
  2068. }
  2069.  
  2070. % An incollection is like inbook, but where there is a separate title
  2071. % for the referenced thing (and perhaps an editor for the whole).
  2072. % An incollection may CROSSREF a book.
  2073. %       Required: author, title, booktitle, publisher, year
  2074. %       Optional: editor, volume or number, series, type, chapter, pages,
  2075. %                       address, edition, month, note
  2076.  
  2077. FUNCTION {incollection}
  2078. { output.bibitem
  2079.   format.authors "author" output.check
  2080. #if NAMED_REFS
  2081.   author format.key output                              % special for
  2082.   output.year.check                                     % apalike
  2083. #endif NAMED_REFS
  2084.   new.block
  2085.   format.title "title" output.check
  2086.   new.block
  2087.   crossref missing$
  2088.     { format.in.ed.booktitle "booktitle" output.check
  2089.       format.bvolume output
  2090.       format.number.series output
  2091.       format.chapter.pages output
  2092.       new.sentence
  2093.       publisher "publisher" output.check
  2094.       address output
  2095.       format.edition output
  2096. #if !NAMED_REFS
  2097.       format.date "year" output.check
  2098. #endif !NAMED_REFS
  2099.     }
  2100.     { format.incoll.inproc.crossref output.nonnull
  2101.       format.chapter.pages output
  2102.     }
  2103.   if$
  2104.   new.block
  2105.   note output
  2106.   fin.entry
  2107. }
  2108.  
  2109. % An inproceedings is an article in a conference proceedings, and it may
  2110. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  2111. % will appear just before note.
  2112. %       Required: author, title, booktitle, year
  2113. %       Optional: editor, volume or number, series, pages, address, month,
  2114. %                       organization, publisher, note
  2115.  
  2116. FUNCTION {inproceedings}
  2117. { output.bibitem
  2118.   format.authors "author" output.check
  2119. #if NAMED_REFS
  2120.   author format.key output                              % special for
  2121.   output.year.check                                     % apalike
  2122. #endif NAMED_REFS
  2123.   new.block
  2124.   format.title "title" output.check
  2125.   new.block
  2126.   crossref missing$
  2127.     { format.in.ed.booktitle "booktitle" output.check
  2128.       format.bvolume output
  2129.       format.number.series output
  2130.       format.pages output
  2131. #if !NAMED_REFS
  2132.       address empty$
  2133.         { organization publisher new.sentence.checkb
  2134.           organization output
  2135.           publisher output
  2136.           format.date "year" output.check
  2137.         }
  2138.         { address output.nonnull
  2139.           format.date "year" output.check
  2140.           new.sentence
  2141.           organization output
  2142.           publisher output
  2143.         }
  2144.       if$
  2145. #else NAMED_REFS
  2146.       address output                                    % for apalike
  2147.       new.sentence                                      % there's no year
  2148.       organization output                               % here so things
  2149.       publisher output                                  % are simpler
  2150. #endif NAMED_REFS
  2151.     }
  2152.     { format.incoll.inproc.crossref output.nonnull
  2153.       format.pages output
  2154.     }
  2155.   if$
  2156.   new.block
  2157.   note output
  2158.   fin.entry
  2159. }
  2160.  
  2161. % The conference function is included for Scribe compatibility.
  2162.  
  2163. FUNCTION {conference} { inproceedings }
  2164.  
  2165. % A manual is technical documentation.
  2166. %       Required: title
  2167. %       Optional: author, organization, address, edition, month, year, note
  2168.  
  2169. FUNCTION {manual}
  2170. { output.bibitem
  2171. #if !NAMED_REFS
  2172.   author empty$
  2173.     { organization empty$
  2174.         'skip$
  2175.         { organization output.nonnull
  2176.           address output
  2177.         }
  2178.       if$
  2179.     }
  2180.     { format.authors output.nonnull }
  2181.   if$
  2182.   new.block
  2183.   format.btitle "title" output.check
  2184.   author empty$
  2185.     { organization empty$
  2186.         { address new.block.checka
  2187.           address output
  2188.         }
  2189.         'skip$
  2190.       if$
  2191.     }
  2192.     { organization address new.block.checkb
  2193.       organization output
  2194.       address output
  2195.     }
  2196.   if$
  2197.   format.edition output
  2198.   format.date output
  2199. #else NAMED_REFS
  2200.   format.authors output
  2201.   author format.key output                              % special for
  2202.   output.year.check                                     % apalike
  2203.   new.block
  2204.   format.btitle "title" output.check
  2205.   organization address new.block.checkb
  2206.   organization output
  2207.   address output
  2208.   format.edition output
  2209. #endif NAMED_REFS
  2210.   new.block
  2211.   note output
  2212.   fin.entry
  2213. }
  2214.  
  2215. % A mastersthesis is a Master's thesis.
  2216. %       Required: author, title, school, year
  2217. %       Optional: type, address, month, note
  2218.  
  2219. FUNCTION {mastersthesis}
  2220. { output.bibitem
  2221.   format.authors "author" output.check
  2222. #if NAMED_REFS
  2223.   author format.key output                              % special for
  2224.   output.year.check                                     % apalike
  2225. #endif NAMED_REFS
  2226.   new.block
  2227.   format.title "title" output.check
  2228.   new.block
  2229.   "Master's thesis" format.thesis.type output.nonnull
  2230.   school "school" output.check
  2231.   address output
  2232. #if !NAMED_REFS
  2233.   format.date "year" output.check
  2234. #endif !NAMED_REFS
  2235.   new.block
  2236.   note output
  2237.   fin.entry
  2238. }
  2239.  
  2240. % A misc is something that doesn't fit elsewhere.
  2241. %       Required: at least one of the `optional' fields
  2242. %       Optional: author, title, howpublished, month, year, note
  2243.  
  2244. FUNCTION {misc}
  2245. { output.bibitem
  2246.   format.authors output
  2247. #if !NAMED_REFS
  2248.   title howpublished new.block.checkb
  2249.   format.title output
  2250.   howpublished new.block.checka
  2251.   howpublished output
  2252.   format.date output
  2253. #else NAMED_REFS
  2254.   author format.key output                              % special for
  2255.   output.year.check                                     % apalike
  2256.   new.block
  2257.   format.title output
  2258.   new.block
  2259.   howpublished output
  2260. #endif NAMED_REFS
  2261.   new.block
  2262.   note output
  2263.   fin.entry
  2264. #if !NAMED_REFS
  2265.   empty.misc.check
  2266. #endif
  2267. }
  2268.  
  2269. % A phdthesis is like a mastersthesis.
  2270. %       Required: author, title, school, year
  2271. %       Optional: type, address, month, note
  2272.  
  2273. FUNCTION {phdthesis}
  2274. { output.bibitem
  2275.   format.authors "author" output.check
  2276. #if NAMED_REFS
  2277.   author format.key output                              % special for
  2278.   output.year.check                                     % apalike
  2279. #endif NAMED_REFS
  2280.   new.block
  2281.   format.btitle "title" output.check
  2282.   new.block
  2283.   "PhD thesis" format.thesis.type output.nonnull
  2284.   school "school" output.check
  2285.   address output
  2286. #if !NAMED_REFS
  2287.   format.date "year" output.check
  2288. #endif !NAMED_REFS
  2289.   new.block
  2290.   note output
  2291.   fin.entry
  2292. }
  2293.  
  2294. % A proceedings is a conference proceedings.
  2295. % If there is an organization but no editor field, the organization will
  2296. % appear as the first optional field (we try to make the first block nonempty);
  2297. % if there's no address field, the month (& year) will appear just before note.
  2298. %       Required: title, year
  2299. %       Optional: editor, volume or number, series, address, month,
  2300. %                       organization, publisher, note
  2301.  
  2302. FUNCTION {proceedings}
  2303. { output.bibitem
  2304. #if !NAMED_REFS
  2305.   editor empty$
  2306.     { organization output }
  2307.     { format.editors output.nonnull }
  2308.   if$
  2309. #else NAMED_REFS
  2310.   format.editors output
  2311.   editor format.key output                              % special for
  2312.   output.year.check                                     % apalike
  2313. #endif NAMED_REFS
  2314.   new.block
  2315.   format.btitle "title" output.check
  2316.   format.bvolume output
  2317.   format.number.series output
  2318. #if !NAMED_REFS
  2319.   address empty$
  2320.     { editor empty$
  2321.         { publisher new.sentence.checka }
  2322.         { organization publisher new.sentence.checkb
  2323.           organization output
  2324.         }
  2325.       if$
  2326.       publisher output
  2327.       format.date "year" output.check
  2328.     }
  2329.     { address output.nonnull
  2330.       format.date "year" output.check
  2331.       new.sentence
  2332.       editor empty$
  2333.         'skip$
  2334.         { organization output }
  2335.       if$
  2336.       publisher output
  2337.     }
  2338.   if$
  2339. #else NAMED_REFS
  2340.   address output                                % for apalike
  2341.   new.sentence                                  % we always output
  2342.   organization output                           % a nonempty organization
  2343.   publisher output                              % here
  2344. #endif NAMED_REFS
  2345.   new.block
  2346.   note output
  2347.   fin.entry
  2348. }
  2349.  
  2350. % A techreport is a technical report.
  2351. %       Required: author, title, institution, year
  2352. %       Optional: type, number, address, month, note
  2353.  
  2354. FUNCTION {techreport}
  2355. { output.bibitem
  2356.   format.authors "author" output.check
  2357. #if NAMED_REFS
  2358.   author format.key output                              % special for
  2359.   output.year.check                                     % apalike
  2360. #endif NAMED_REFS
  2361.   new.block
  2362.   format.title "title" output.check
  2363.   new.block
  2364.   format.tr.number output.nonnull
  2365.   institution "institution" output.check
  2366.   address output
  2367. #if !NAMED_REFS
  2368.   format.date "year" output.check
  2369. #endif !NAMED_REFS
  2370.   new.block
  2371.   note output
  2372.   fin.entry
  2373. }
  2374.  
  2375. % An unpublished is something that hasn't been published.
  2376. %       Required: author, title, note
  2377. %       Optional: month, year
  2378.  
  2379. FUNCTION {unpublished}
  2380. { output.bibitem
  2381.   format.authors "author" output.check
  2382. #if NAMED_REFS
  2383.   author format.key output                              % special for
  2384.   output.year.check                                     % apalike
  2385. #endif NAMED_REFS
  2386.   new.block
  2387.   format.title "title" output.check
  2388.   new.block
  2389.   note "note" output.check
  2390. #if !NAMED_REFS
  2391.   format.date output
  2392. #endif
  2393.   fin.entry
  2394. }
  2395.  
  2396. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  2397.  
  2398. FUNCTION {default.type} { misc }
  2399.  
  2400. % Here are macros for common things that may vary from style to style.
  2401. % Users are encouraged to use these macros.
  2402. %
  2403. % Months are either written out in full or abbreviated
  2404.  
  2405. #if MONTH_FULL
  2406.  
  2407. MACRO {jan} {"January"}
  2408.  
  2409. MACRO {feb} {"February"}
  2410.  
  2411. MACRO {mar} {"March"}
  2412.  
  2413. MACRO {apr} {"April"}
  2414.  
  2415. MACRO {may} {"May"}
  2416.  
  2417. MACRO {jun} {"June"}
  2418.  
  2419. MACRO {jul} {"July"}
  2420.  
  2421. MACRO {aug} {"August"}
  2422.  
  2423. MACRO {sep} {"September"}
  2424.  
  2425. MACRO {oct} {"October"}
  2426.  
  2427. MACRO {nov} {"November"}
  2428.  
  2429. MACRO {dec} {"December"}
  2430.  
  2431. #else !MONTH_FULL
  2432.  
  2433. MACRO {jan} {"Jan."}
  2434.  
  2435. MACRO {feb} {"Feb."}
  2436.  
  2437. MACRO {mar} {"Mar."}
  2438.  
  2439. MACRO {apr} {"Apr."}
  2440.  
  2441. MACRO {may} {"May"}
  2442.  
  2443. MACRO {jun} {"June"}
  2444.  
  2445. MACRO {jul} {"July"}
  2446.  
  2447. MACRO {aug} {"Aug."}
  2448.  
  2449. MACRO {sep} {"Sept."}
  2450.  
  2451. MACRO {oct} {"Oct."}
  2452.  
  2453. MACRO {nov} {"Nov."}
  2454.  
  2455. MACRO {dec} {"Dec."}
  2456.  
  2457. #endif MONTH_FULL
  2458.  
  2459. % Journals are either written out in full or abbreviated;
  2460. % the abbreviations are like those found in ACM publications.
  2461. %
  2462. % To get a completely different set of abbreviations, it may be best to make
  2463. % a separate .bib file with nothing but those abbreviations; users could then
  2464. % include that file name as the first argument to the \bibliography command
  2465.  
  2466. #if JOUR_FULL
  2467.  
  2468. MACRO {acmcs} {"ACM Computing Surveys"}
  2469.  
  2470. MACRO {acta} {"Acta Informatica"}
  2471.  
  2472. MACRO {cacm} {"Communications of the ACM"}
  2473.  
  2474. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  2475.  
  2476. MACRO {ibmsj} {"IBM Systems Journal"}
  2477.  
  2478. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  2479.  
  2480. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  2481.  
  2482. MACRO {ieeetcad}
  2483.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  2484.  
  2485. MACRO {ipl} {"Information Processing Letters"}
  2486.  
  2487. MACRO {jacm} {"Journal of the ACM"}
  2488.  
  2489. MACRO {jcss} {"Journal of Computer and System Sciences"}
  2490.  
  2491. MACRO {scp} {"Science of Computer Programming"}
  2492.  
  2493. MACRO {sicomp} {"SIAM Journal on Computing"}
  2494.  
  2495. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  2496.  
  2497. MACRO {tods} {"ACM Transactions on Database Systems"}
  2498.  
  2499. MACRO {tog} {"ACM Transactions on Graphics"}
  2500.  
  2501. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  2502.  
  2503. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  2504.  
  2505. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  2506.  
  2507. MACRO {tcs} {"Theoretical Computer Science"}
  2508.  
  2509. #else !JOUR_FULL
  2510.  
  2511. MACRO {acmcs} {"ACM Comput. Surv."}
  2512.  
  2513. MACRO {acta} {"Acta Inf."}
  2514.  
  2515. MACRO {cacm} {"Commun. ACM"}
  2516.  
  2517. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  2518.  
  2519. MACRO {ibmsj} {"IBM Syst.~J."}
  2520.  
  2521. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  2522.  
  2523. MACRO {ieeetc} {"IEEE Trans. Comput."}
  2524.  
  2525. MACRO {ieeetcad}
  2526.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  2527.  
  2528. MACRO {ipl} {"Inf. Process. Lett."}
  2529.  
  2530. MACRO {jacm} {"J.~ACM"}
  2531.  
  2532. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  2533.  
  2534. MACRO {scp} {"Sci. Comput. Programming"}
  2535.  
  2536. MACRO {sicomp} {"SIAM J. Comput."}
  2537.  
  2538. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  2539.  
  2540. MACRO {tods} {"ACM Trans. Database Syst."}
  2541.  
  2542. MACRO {tog} {"ACM Trans. Gr."}
  2543.  
  2544. MACRO {toms} {"ACM Trans. Math. Softw."}
  2545.  
  2546. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  2547.  
  2548. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  2549.  
  2550. MACRO {tcs} {"Theoretical Comput. Sci."}
  2551.  
  2552. #if PHYSICS_JOUR
  2553. #include "journal-abbrev.bst"
  2554. #endif PHYSICS_JOUR
  2555.  
  2556. #endif JOUR_FULL
  2557.  
  2558. % Now we read in the .BIB entries.
  2559.  
  2560. READ
  2561.  
  2562. % The sortify function converts to lower case after purify$ing; it's
  2563. % used in sorting and in computing alphabetic labels after sorting
  2564. %
  2565. % The chop.word(w,len,s) function returns either s or, if the first len
  2566. % letters of s equals w (this comparison is done in the third line of the
  2567. % function's definition), it returns that part of s after w.
  2568.  
  2569. #if SORTED
  2570.  
  2571. FUNCTION {sortify}
  2572. { purify$
  2573.   "l" change.case$
  2574. }
  2575.  
  2576. INTEGERS { len }
  2577.  
  2578. FUNCTION {chop.word}
  2579. { 's :=
  2580.   'len :=
  2581.   s #1 len substring$ =
  2582.     { s len #1 + global.max$ substring$ }
  2583.     's
  2584.   if$
  2585. }
  2586.  
  2587. #else !SORTED
  2588. #if LAB_ALPH
  2589.  
  2590. % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
  2591.  
  2592. INTEGERS { len }
  2593.  
  2594. FUNCTION {chop.word}
  2595. { 's :=
  2596.   'len :=
  2597.   s #1 len substring$ =
  2598.     { s len #1 + global.max$ substring$ }
  2599.     's
  2600.   if$
  2601. }
  2602.  
  2603. #endif LAB_ALPH
  2604. #endif SORTED
  2605.  
  2606. % This long comment applies only to alphabetic labels
  2607. %
  2608. % The format.lab.names function makes a short label by using the initials of
  2609. % the von and Last parts of the names (but if there are more than four names,
  2610. % (i.e., people) it truncates after three and adds a superscripted "+";
  2611. % it also adds such a "+" if the last of multiple authors is "others").
  2612. % If there is only one name, and its von and Last parts combined have just
  2613. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  2614. % we take the first three letters of the last name.  The boolean
  2615. % et.al.char.used tells whether we've used a superscripted "+", so that we
  2616. % know whether to include a LaTeX macro for it.
  2617. %
  2618. % format.lab.names(s) ==
  2619. %  BEGIN
  2620. %       numnames := num.names$(s)
  2621. %       if numnames > 1 then
  2622. %           if numnames > 4 then
  2623. %               namesleft := 3
  2624. %           else
  2625. %               namesleft := numnames
  2626. %           nameptr := 1
  2627. %           nameresult := ""
  2628. %           while namesleft > 0
  2629. %             do
  2630. %               if (name_ptr = numnames) and
  2631. %                    format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  2632. %                  then nameresult := nameresult * "{\etalchar{+}}"
  2633. %                       et.al.char.used := true
  2634. %                  else nameresult := nameresult *
  2635. %                               format.name$(s, nameptr, "{v{}}{l{}}")
  2636. %               nameptr := nameptr + 1
  2637. %               namesleft := namesleft - 1
  2638. %             od
  2639. %           if numnames > 4 then
  2640. %               nameresult := nameresult * "{\etalchar{+}}"
  2641. %               et.al.char.used := true
  2642. %       else
  2643. %           t := format.name$(s, 1, "{v{}}{l{}}")
  2644. %           if text.length$(t) < 2 then % there's just one name-token
  2645. %               nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  2646. %           else
  2647. %               nameresult := t
  2648. %           fi
  2649. %       fi
  2650. %       return nameresult
  2651. %  END
  2652. %
  2653. % Exactly what fields we look at in constructing the primary part of the label
  2654. % depends on the entry type; this selectivity (as opposed to, say, always
  2655. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  2656. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  2657. % of the deepest `else' clause in the nested part of calc.label; thus, any
  2658. % unrecognized entry type in the database is handled correctly.
  2659. %
  2660. % There is one auxiliary function for each of the four different sequences of
  2661. % fields we use.  The first of these functions looks at the author field, and
  2662. % then, if necessary, the key field.  The other three functions, which might
  2663. % look at two fields and the key field, are similar, except that the key field
  2664. % takes precedence over the organization field (for labels---not for sorting).
  2665. %
  2666. % The calc.label function calculates the preliminary label of an entry, which
  2667. % is formed by taking three letters of information from the author or editor or
  2668. % key or organization field (depending on the entry type and on what's empty,
  2669. % but ignoring a leading "The " in the organization), and appending the last
  2670. % two characters (digits) of the year. It is an error if the appropriate fields
  2671. % among author, editor, organization, and key are missing, and we use
  2672. % the first three letters of the cite$ in desperation when this happens.
  2673. % The resulting label has the year part, but not the name part, purify$ed
  2674. % (purify$ing the year allows some sorting shenanigans by the user).
  2675. %
  2676. % This function also calculates the version of the label to be used in sorting.
  2677. %
  2678. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  2679. % otherwise identical labels, but we can't calculated those "extra.label"s
  2680. % until after sorting.
  2681. %
  2682. % calc.label ==
  2683. %  BEGIN
  2684. %       if type$ = "book" or "inbook" then
  2685. %           author.editor.key.label
  2686. %       else if type$ = "proceedings" then
  2687. %           editor.key.organization.label
  2688. %       else if type$ = "manual" then
  2689. %           author.key.organization.label
  2690. %       else
  2691. %           author.key.label
  2692. %       fi fi fi
  2693. %       label := label * substring$(purify$(field.or.null(year)), -1, 2)
  2694. %               % assuming we will also sort, we calculate a sort.label
  2695. %       sort.label := sortify(label), but use the last four, not two, digits
  2696. %  END
  2697.  
  2698. #if LAB_ALPH
  2699.  
  2700. #if !NAMED_REFS
  2701. INTEGERS { et.al.char.used }
  2702.  
  2703. FUNCTION {initialize.et.al.char.used}
  2704. { #0 'et.al.char.used :=
  2705. }
  2706.  
  2707. EXECUTE {initialize.et.al.char.used}
  2708. #endif !NAMED_REFS
  2709.  
  2710. #if !NAMED_REFS
  2711. FUNCTION {format.lab.names}
  2712. #if !RMP_LABELS
  2713. { 's :=
  2714.   s num.names$ 'numnames :=
  2715.   numnames #1 >
  2716.     { numnames #4 >
  2717.         { #3 'namesleft := }
  2718.         { numnames 'namesleft := }
  2719.       if$
  2720.       #1 'nameptr :=
  2721.       ""
  2722.         { namesleft #0 > }
  2723.         { nameptr numnames =
  2724.             { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2725.                 { "{\etalchar{+}}" *
  2726.                   #1 'et.al.char.used :=
  2727.                 }
  2728.                 { s nameptr "{v{}}{l{}}" format.name$ * }
  2729.               if$
  2730.             }
  2731.             { s nameptr "{v{}}{l{}}" format.name$ * }
  2732.           if$
  2733.           nameptr #1 + 'nameptr :=
  2734.           namesleft #1 - 'namesleft :=
  2735.         }
  2736.       while$
  2737.       numnames #4 >
  2738.         { "{\etalchar{+}}" *
  2739.           #1 'et.al.char.used :=
  2740.         }
  2741.         'skip$
  2742.       if$
  2743.     }
  2744.     { s #1 "{v{}}{l{}}" format.name$
  2745.       duplicate$ text.length$ #2 <
  2746.         { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
  2747.         'skip$
  2748.       if$
  2749.     }
  2750.   if$
  2751. }
  2752. #else RMP_LABELS
  2753. { 's :=
  2754.   s num.names$ 'numnames :=
  2755.   numnames #1 >
  2756.     { numnames #2 >
  2757. #if !CSC_NAMES
  2758. #if !ETAL_EMPH
  2759.        { s #1 "{vv }{ll}" format.name$ " et~al." * }
  2760. #else ETAL_EMPH
  2761.        { s #1 "{vv }{ll}" format.name$ " {\em et~al.}" * }
  2762. #endif ETAL_EMPH
  2763.        { s #1 "{vv }{ll}" format.name$
  2764. #else CSC_NAMES
  2765. #if !ETAL_EMPH
  2766.        { s #1 "{vv }{ll}" format.name$ caps " et~al." * }
  2767. #else ETAL_EMPH
  2768.        { s #1 "{vv }{ll}" format.name$ caps " {\em et~al.}" * }
  2769. #endif ETAL_EMPH
  2770.        { s #1 "{vv }{ll}" format.name$ caps
  2771. #endif CSC_NAMES
  2772.          s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2773. #if !ETAL_EMPH
  2774.             { " et~al." * }
  2775. #else ETAL_EMPH
  2776.             { " {\em et~al.}" * }
  2777. #endif ETAL_EMPH
  2778. #if !CSC_NAMES
  2779.             { " and " * s #2 "{vv }{ll}" format.name$ * }
  2780. #else CSC_NAMES
  2781.             { " and " * s #2 "{vv }{ll}" format.name$ caps * }
  2782. #endif CSC_NAMES
  2783.          if$
  2784.        }
  2785.       if$
  2786.     }
  2787. #if !CSC_NAMES
  2788.     { s #1 "{vv }{ll}" format.name$ }
  2789. #else CSC_NAMES
  2790.     { s #1 "{vv }{ll}" format.name$ caps }
  2791. #endif
  2792.   if$
  2793. }
  2794. #endif
  2795. #else NAMED_REFS
  2796. %                       There are three apalike cases: one person (Jones),
  2797. %                       two (Jones and de~Bruijn), and more (Jones et~al.).
  2798. %                       This function is much like format.crossref.editors.
  2799. %
  2800. FUNCTION {format.lab.names}
  2801. { 's :=
  2802. #if !CSC_NAMES
  2803.   s #1 "{vv~}{ll}" format.name$
  2804. #else CSC_NAMES
  2805.   s #1 "{vv~}{ll}" format.name$ caps
  2806. #endif CSC_NAMES
  2807.   s num.names$ duplicate$
  2808.   #2 >
  2809. #if !ETAL_EMPH
  2810.     { pop$ " et~al." * }
  2811. #else ETAL_EMPH
  2812.     { pop$ " {\em et~al.}" * }
  2813. #endif ETAL_EMPH
  2814.     { #2 <
  2815.         'skip$
  2816.         { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  2817. #if !ETAL_EMPH
  2818.             { " et~al." * }
  2819. #else ETAL_EMPH
  2820.             { " {\em et~al.}" * }
  2821. #endif ETAL_EMPH
  2822. #if !CSC_NAMES
  2823.             { " and " * s #2 "{vv~}{ll}" format.name$ * }
  2824. #else CSC_NAMES
  2825.             { " and " * s #2 "{vv~}{ll}" format.name$ caps * }
  2826. #endif
  2827.           if$
  2828.         }
  2829.       if$
  2830.     }
  2831.   if$
  2832. }
  2833. #endif NAMED_REFS
  2834.  
  2835. FUNCTION {author.key.label}
  2836. { author empty$
  2837.     { key empty$
  2838. #if SORTED
  2839.         { cite$ #1 #3 substring$ }
  2840. #else !SORTED           % need warning here because we won't give it later
  2841.         { "for label, need author or key in " cite$ * warning$
  2842.           cite$ #1 #3 substring$
  2843.         }
  2844. #endif SORTED
  2845. #if !NAMED_REFS
  2846.         { key #3 text.prefix$ }
  2847. #else NAMED_REFS
  2848.         'key                                    % apalike uses the whole key
  2849. #endif NAMED_REFS
  2850.       if$
  2851.     }
  2852.     { author format.lab.names }
  2853.   if$
  2854. }
  2855.  
  2856. FUNCTION {author.editor.key.label}
  2857. { author empty$
  2858.     { editor empty$
  2859.         { key empty$
  2860. #if SORTED
  2861.             { cite$ #1 #3 substring$ }
  2862. #else !SORTED           % need warning here because we won't give it later
  2863.             { "for label, need author, editor, or key in " cite$ * warning$
  2864.               cite$ #1 #3 substring$
  2865.             }
  2866. #endif SORTED
  2867. #if !NAMED_REFS
  2868.             { key #3 text.prefix$ }
  2869. #else NAMED_REFS
  2870.             'key                                % apalike uses the whole key
  2871. #endif NAMED_REFS
  2872.           if$
  2873.         }
  2874.         { editor format.lab.names }
  2875.       if$
  2876.     }
  2877.     { author format.lab.names }
  2878.   if$
  2879. }
  2880.  
  2881. #if !NAMED_REFS
  2882. FUNCTION {author.key.organization.label}
  2883. { author empty$
  2884.     { key empty$
  2885.         { organization empty$
  2886. #if SORTED
  2887.             { cite$ #1 #3 substring$ }
  2888. #else !SORTED           % need warning here because we won't give it later
  2889.             { "for label, need author, key, or organization in " cite$ *
  2890.                                                                 warning$
  2891.               cite$ #1 #3 substring$
  2892.             }
  2893. #endif SORTED
  2894. #if !RMP_LABELS
  2895.             { "The " #4 organization chop.word #3 text.prefix$ }
  2896. #else RMP_LABELS
  2897.             { "The " #4 organization chop.word #9 text.prefix$ }
  2898. #endif
  2899.           if$
  2900.         }
  2901.         { key #3 text.prefix$ }
  2902.       if$
  2903.     }
  2904.     { author format.lab.names }
  2905.   if$
  2906. }
  2907.  
  2908. FUNCTION {editor.key.organization.label}
  2909. { editor empty$
  2910.     { key empty$
  2911.         { organization empty$
  2912. #if SORTED
  2913.             { cite$ #1 #3 substring$ }
  2914. #else !SORTED           % need warning here because we won't give it later
  2915.             { "for label, need editor, key, or organization in " cite$ *
  2916.                                                                 warning$
  2917.               cite$ #1 #3 substring$
  2918.             }
  2919. #endif SORTED
  2920. #if !RMP_LABELS
  2921.             { "The " #4 organization chop.word #3 text.prefix$ }
  2922. #else RMP_LABELS
  2923.             { "The " #4 organization chop.word #9 text.prefix$ }
  2924. #endif
  2925.           if$
  2926.         }
  2927.         { key #3 text.prefix$ }
  2928.       if$
  2929.     }
  2930.     { editor format.lab.names }
  2931.   if$
  2932. }
  2933. #else NAMED_REFS
  2934. FUNCTION {editor.key.label}
  2935. { editor empty$
  2936.     { key empty$
  2937.         { cite$ #1 #3 substring$ }
  2938.         'key                    % apalike uses the whole key, no organization
  2939.       if$
  2940.     }
  2941.     { editor format.lab.names }
  2942.   if$
  2943. }
  2944. #endif NAMED_REFS
  2945.  
  2946. FUNCTION {calc.label}
  2947. #if !KEY_CITE
  2948. { type$ "book" =
  2949.   type$ "inbook" =
  2950.   or
  2951.     'author.editor.key.label
  2952.     { type$ "proceedings" =
  2953. #if !NAMED_REFS
  2954.         'editor.key.organization.label
  2955.         { type$ "manual" =
  2956.             'author.key.organization.label
  2957.             'author.key.label
  2958.           if$
  2959.         }
  2960. #else NAMED_REFS
  2961.         'editor.key.label                       % apalike ignores organization
  2962.         'author.key.label                       % for labeling and sorting
  2963. #endif NAMED_REFS
  2964.       if$
  2965.     }
  2966.   if$
  2967. #if !NAMED_REFS
  2968.   duplicate$
  2969. #if !RMP_LABELS
  2970.   year field.or.null purify$ #-1 #2 substring$
  2971. #else RMP_LABELS
  2972.   " " * year field.or.null purify$ #-1 #4 substring$
  2973. #endif
  2974.   *
  2975.   'label :=
  2976.   year field.or.null purify$ #-1 #4 substring$
  2977.   *
  2978.   sortify 'sort.label :=
  2979. #else NAMED_REFS
  2980.   ", "                                                  % these three lines are
  2981.   *                                                     % for apalike, which
  2982.   year field.or.null purify$ #-1 #4 substring$          % uses all four digits
  2983.   *
  2984.   'label :=
  2985. #endif NAMED_REFS
  2986. }
  2987. #else KEY_CITE
  2988. { cite$ 'label :=
  2989. label sortify 'sort.label :=
  2990. }
  2991. #endif
  2992.  
  2993. % It doesn't seem like a particularly good idea to use an order-of-citation
  2994. % reference list when using alphabetic labels, but we need to have a
  2995. % special pass to calculate labels when this happens.
  2996.  
  2997. #if !SORTED
  2998.  
  2999. ITERATE {calc.label}
  3000.  
  3001. #endif !SORTED
  3002.  
  3003. #endif LAB_ALPH
  3004.  
  3005. % When sorting, we compute the sortkey by executing "presort" on each entry.
  3006. % The presort key contains a number of "sortify"ed strings, concatenated
  3007. % with multiple blanks between them.  This makes things like "brinch  per"
  3008. % come before "brinch hansen  per".
  3009. %
  3010. % The fields used here are: the sort.label for alphabetic labels (as set by
  3011. % calc.label), followed by the author names (or editor names or organization
  3012. % (with a leading "The " removed) or key field, depending on entry type and on
  3013. % what's empty), followed by year, followed by the first bit of the title
  3014. % (chopping off a leading "The ", "A ", or "An ").
  3015. % Names are formatted: Von Last First Junior.
  3016. % The names within a part will be separated by a single blank
  3017. % (such as "brinch hansen"), two will separate the name parts themselves
  3018. % (except the von and last), three will separate the names,
  3019. % four will separate the names from year (and from label, if alphabetic),
  3020. % and four will separate year from title.
  3021. %
  3022. % The sort.format.names function takes an argument that should be in
  3023. % BibTeX name format, and returns a string containing "   "-separated
  3024. % names in the format described above.  The function is almost the same
  3025. % as format.names.
  3026.  
  3027. #if SORTED
  3028.  
  3029. FUNCTION {sort.format.names}
  3030. { 's :=
  3031.   #1 'nameptr :=
  3032.   ""
  3033.   s num.names$ 'numnames :=
  3034.   numnames 'namesleft :=
  3035.     { namesleft #0 > }
  3036.     { nameptr #1 >
  3037.         { "   " * }
  3038.         'skip$
  3039. #if NAME_FULL
  3040.       if$
  3041.       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
  3042. #else
  3043.       if$                                               % apalike uses initials
  3044.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  3045. #endif NAME_FULL
  3046.       nameptr numnames = t "others" = and
  3047.         { "et al" * }
  3048.         { t sortify * }
  3049.       if$
  3050.       nameptr #1 + 'nameptr :=
  3051.       namesleft #1 - 'namesleft :=
  3052.     }
  3053.   while$
  3054. }
  3055.  
  3056. % The sort.format.title function returns the argument,
  3057. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  3058. % The chop.word function uses s, so we need another string variable, t
  3059.  
  3060. FUNCTION {sort.format.title}
  3061. { 't :=
  3062.   "A " #2
  3063.     "An " #3
  3064.       "The " #4 t chop.word
  3065.     chop.word
  3066.   chop.word
  3067.   sortify
  3068.   #1 global.max$ substring$
  3069. }
  3070.  
  3071. % The auxiliary functions here, for the presort function, are analogous to
  3072. % the ones for calc.label; the same comments apply, except that the
  3073. % organization field takes precedence here over the key field.  For sorting
  3074. % purposes, we still remove a leading "The " from the organization field.
  3075.  
  3076. FUNCTION {author.sort}
  3077. { author empty$
  3078.     { key empty$
  3079.         { "to sort, need author or key in " cite$ * warning$
  3080.           ""
  3081.         }
  3082.         { key sortify }
  3083.       if$
  3084.     }
  3085.     { author sort.format.names }
  3086.   if$
  3087. }
  3088.  
  3089. FUNCTION {author.editor.sort}
  3090. { author empty$
  3091.     { editor empty$
  3092.         { key empty$
  3093.             { "to sort, need author, editor, or key in " cite$ * warning$
  3094.               ""
  3095.             }
  3096.             { key sortify }
  3097.           if$
  3098.         }
  3099.         { editor sort.format.names }
  3100.       if$
  3101.     }
  3102.     { author sort.format.names }
  3103.   if$
  3104. }
  3105.  
  3106. #if !NAMED_REFS
  3107. FUNCTION {author.organization.sort}
  3108. { author empty$
  3109.     { organization empty$
  3110.         { key empty$
  3111.             { "to sort, need author, organization, or key in " cite$ * warning$
  3112.               ""
  3113.             }
  3114.             { key sortify }
  3115.           if$
  3116.         }
  3117.         { "The " #4 organization chop.word sortify }
  3118.       if$
  3119.     }
  3120.     { author sort.format.names }
  3121.   if$
  3122. }
  3123.  
  3124. FUNCTION {editor.organization.sort}
  3125. { editor empty$
  3126.     { organization empty$
  3127.         { key empty$
  3128.             { "to sort, need editor, organization, or key in " cite$ * warning$
  3129.               ""
  3130.             }
  3131.             { key sortify }
  3132.           if$
  3133.         }
  3134.         { "The " #4 organization chop.word sortify }
  3135.       if$
  3136.     }
  3137.     { editor sort.format.names }
  3138.   if$
  3139. }
  3140. #else NAMED_REFS
  3141. FUNCTION {editor.sort}
  3142. { editor empty$
  3143.     { key empty$
  3144.         { "to sort, need editor or key in " cite$ * warning$
  3145.           ""
  3146.         }
  3147.         { key sortify }
  3148.       if$
  3149.     }
  3150.     { editor sort.format.names }
  3151.   if$
  3152. }
  3153. #endif NAMED_REFS
  3154.  
  3155. #if !NAMED_REFS
  3156. % There is a limit, entry.max$, on the length of an entry string variable
  3157. % (which is what its sort.key$ is), so we take at most that many characters
  3158. % of the constructed key, and hope there aren't many references that match
  3159. % to that many characters!
  3160.  
  3161. FUNCTION {presort}
  3162. #if LAB_ALPH
  3163. { calc.label
  3164.   sort.label
  3165.   "    "
  3166.   *
  3167.   type$ "book" =
  3168. #else !LAB_ALPH
  3169. { type$ "book" =
  3170. #endif LAB_ALPH
  3171.   type$ "inbook" =
  3172.   or
  3173.     'author.editor.sort
  3174.     { type$ "proceedings" =
  3175.         'editor.organization.sort
  3176.         { type$ "manual" =
  3177.             'author.organization.sort
  3178.             'author.sort
  3179.           if$
  3180.         }
  3181.       if$
  3182.     }
  3183.   if$
  3184. #if LAB_ALPH
  3185.   *
  3186. #endif LAB_ALPH
  3187.   "    "
  3188.   *
  3189.   year field.or.null sortify
  3190.   *
  3191.   "    "
  3192.   *
  3193.   title field.or.null
  3194.   sort.format.title
  3195.   *
  3196.   #1 entry.max$ substring$
  3197.   'sort.key$ :=
  3198. }
  3199. #else NAMED_REFS
  3200. %                       apalike uses two sorting passes; the first one sets the
  3201. %                       labels so that the `a's, `b's, etc. can be computed;
  3202. %                       the second pass puts the references in "correct" order.
  3203. %                       The presort function is for the first pass. It computes
  3204. %                       label, sort.label, and title, and then concatenates.
  3205. FUNCTION {presort}
  3206. { calc.label
  3207.   label sortify
  3208.   "    "
  3209.   *
  3210.   type$ "book" =
  3211.   type$ "inbook" =
  3212.   or
  3213.     'author.editor.sort
  3214.     { type$ "proceedings" =
  3215.         'editor.sort
  3216.         'author.sort
  3217.       if$
  3218.     }
  3219.   if$
  3220.   #1 entry.max$ substring$      % for
  3221.   'sort.label :=                % apalike
  3222.   sort.label                    % style
  3223.   *
  3224.   "    "
  3225.   *
  3226.   title field.or.null
  3227.   sort.format.title
  3228.   *
  3229.   #1 entry.max$ substring$
  3230.   'sort.key$ :=
  3231. }
  3232. #endif NAMED_REFS
  3233.  
  3234. ITERATE {presort}
  3235.  
  3236. % And now we can sort
  3237.  
  3238. #if !NAMED_REFS
  3239. SORT
  3240. #else NAMED_REFS
  3241. SORT            % by label, sort.label, title---for final label calculation
  3242. #endif
  3243.  
  3244. #endif SORTED
  3245.  
  3246. % This long comment applies only to alphabetic labels, when sorted
  3247. %
  3248. % Now comes the final computation for alphabetic labels, putting in the 'a's
  3249. % and 'b's and so forth if required.  This involves two passes: a forward
  3250. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  3251. % to put in the 'a's (we don't want to put in 'a's unless we know there
  3252. % are 'b's).
  3253. % We have to keep track of the longest (in width$ terms) label, for use
  3254. % by the "thebibliography" environment.
  3255. %
  3256. % VAR: longest.label, last.sort.label, next.extra: string
  3257. %      longest.label.width, last.extra.num: integer
  3258. %
  3259. % initialize.longest.label ==
  3260. %  BEGIN
  3261. %       longest.label := ""
  3262. %       last.sort.label := int.to.chr$(0)
  3263. %       next.extra := ""
  3264. %       longest.label.width := 0
  3265. %       last.extra.num := 0
  3266. %  END
  3267. %
  3268. % forward.pass ==
  3269. %  BEGIN
  3270. %       if last.sort.label = sort.label then
  3271. %           last.extra.num := last.extra.num + 1
  3272. %           extra.label := int.to.chr$(last.extra.num)
  3273. %       else
  3274. %           last.extra.num := chr.to.int$("a")
  3275. %           extra.label := ""
  3276. %           last.sort.label := sort.label
  3277. %       fi
  3278. %  END
  3279. %
  3280. % reverse.pass ==
  3281. %  BEGIN
  3282. %       if next.extra = "b" then
  3283. %           extra.label := "a"
  3284. %       fi
  3285. %       label := label * extra.label
  3286. %       if width$(label) > longest.label.width then
  3287. %           longest.label := label
  3288. %           longest.label.width := width$(label)
  3289. %       fi
  3290. %       next.extra := extra.label
  3291. %  END
  3292.  
  3293. #if LAB_ALPH
  3294.  
  3295. #if SORTED
  3296.  
  3297. #if !NAMED_REFS
  3298. STRINGS { longest.label last.sort.label next.extra }
  3299.  
  3300. INTEGERS { longest.label.width last.extra.num }
  3301.  
  3302. FUNCTION {initialize.longest.label}
  3303. { "" 'longest.label :=
  3304.   #0 int.to.chr$ 'last.sort.label :=
  3305.   "" 'next.extra :=
  3306.   #0 'longest.label.width :=
  3307.   #0 'last.extra.num :=
  3308. }
  3309.  
  3310. FUNCTION {forward.pass}
  3311. { last.sort.label sort.label =
  3312.     { last.extra.num #1 + 'last.extra.num :=
  3313.       last.extra.num int.to.chr$ 'extra.label :=
  3314.     }
  3315.     { "a" chr.to.int$ 'last.extra.num :=
  3316.       "" 'extra.label :=
  3317.       sort.label 'last.sort.label :=
  3318.     }
  3319.   if$
  3320. }
  3321. #else NAMED_REFS
  3322. STRINGS { last.label next.extra }       % apalike labels are only for the text;
  3323.  
  3324. INTEGERS { last.extra.num }             % there are none in the bibliography
  3325.  
  3326. FUNCTION {initialize.extra.label.stuff} % and hence there is no `longest.label'
  3327. { #0 int.to.chr$ 'last.label :=
  3328.   "" 'next.extra :=
  3329.   #0 'last.extra.num :=
  3330. }
  3331.  
  3332. FUNCTION {forward.pass}
  3333. { last.label label =
  3334.     { last.extra.num #1 + 'last.extra.num :=
  3335.       last.extra.num int.to.chr$ 'extra.label :=
  3336.     }
  3337.     { "a" chr.to.int$ 'last.extra.num :=
  3338.       "" 'extra.label :=
  3339.       label 'last.label :=
  3340.     }
  3341.   if$
  3342. }
  3343. #endif NAMED_REFS
  3344.  
  3345. FUNCTION {reverse.pass}
  3346. { next.extra "b" =
  3347.     { "a" 'extra.label := }
  3348.     'skip$
  3349.   if$
  3350.   label extra.label * 'label :=
  3351. #if !NAMED_REFS
  3352.   label width$ longest.label.width >
  3353.     { label 'longest.label :=
  3354.       label width$ 'longest.label.width :=
  3355.     }
  3356.     'skip$
  3357.   if$
  3358. #endif !NAMED_REFS
  3359.   extra.label 'next.extra :=
  3360. }
  3361.  
  3362. #if !NAMED_REFS
  3363. EXECUTE {initialize.longest.label}
  3364. #else NAMED_REFS
  3365. EXECUTE {initialize.extra.label.stuff}
  3366. #endif NAMED_REFS
  3367.  
  3368. ITERATE {forward.pass}
  3369.  
  3370. REVERSE {reverse.pass}
  3371.  
  3372. #if NAMED_REFS
  3373. %                               Now that the label is right we sort for real,
  3374. %                               on sort.label then year then title.  This is
  3375. %                               for the second sorting pass.
  3376. FUNCTION {bib.sort.order}
  3377. { sort.label
  3378.   "    "
  3379.   *
  3380.   year field.or.null sortify
  3381.   *
  3382.   "    "
  3383.   *
  3384.   title field.or.null
  3385.   sort.format.title
  3386.   *
  3387.   #1 entry.max$ substring$
  3388.   'sort.key$ :=
  3389. }
  3390.  
  3391. ITERATE {bib.sort.order}
  3392.  
  3393. SORT            % by sort.label, year, title---giving final bibliography order
  3394. #endif NAMED_REFS
  3395. #else !SORTED
  3396.  
  3397. % It still doesn't seem like a good idea to use an order-of-citation
  3398. % reference list when using alphabetic labels, but when this happens we
  3399. % must compute the longest label
  3400.  
  3401. STRINGS { longest.label }
  3402.  
  3403. INTEGERS { longest.label.width }
  3404.  
  3405. FUNCTION {initialize.longest.label}
  3406. { "" 'longest.label :=
  3407.   #0 'longest.label.width :=
  3408. }
  3409.  
  3410. FUNCTION {longest.label.pass}
  3411. { label width$ longest.label.width >
  3412.     { label 'longest.label :=
  3413.       label width$ 'longest.label.width :=
  3414.     }
  3415.     'skip$
  3416.   if$
  3417. }
  3418.  
  3419. EXECUTE {initialize.longest.label}
  3420.  
  3421. ITERATE {longest.label.pass}
  3422.  
  3423. #endif SORTED
  3424.  
  3425. #else !LAB_ALPH
  3426.  
  3427. % Now comes the computation for numeric labels.
  3428. % We use either the sorted order or original order.
  3429. % We still have to keep track of the longest (in width$ terms) label, for use
  3430. % by the "thebibliography" environment.
  3431.  
  3432. STRINGS { longest.label }
  3433.  
  3434. INTEGERS { number.label longest.label.width }
  3435.  
  3436. FUNCTION {initialize.longest.label}
  3437. { "" 'longest.label :=
  3438.   #1 'number.label :=
  3439.   #0 'longest.label.width :=
  3440. }
  3441.  
  3442. FUNCTION {longest.label.pass}
  3443. { number.label int.to.str$ 'label :=
  3444.   number.label #1 + 'number.label :=
  3445.   label width$ longest.label.width >
  3446.     { label 'longest.label :=
  3447.       label width$ 'longest.label.width :=
  3448.     }
  3449.     'skip$
  3450.   if$
  3451. }
  3452.  
  3453. EXECUTE {initialize.longest.label}
  3454.  
  3455. ITERATE {longest.label.pass}
  3456.  
  3457. #endif LAB_ALPH
  3458.  
  3459. % Now we're ready to start writing the .BBL file.
  3460. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  3461. % label; next comes stuff from the `preamble' command in the database files.
  3462. % Then we give an incantation containing the command
  3463. %     \begin{thebibliography}{...}
  3464. % where the `...' is the longest label.
  3465. %
  3466. % We also call init.state.consts, for use by the output routines.
  3467.  
  3468. FUNCTION {begin.bib}
  3469. #if !NAMED_REFS
  3470. #if LAB_ALPH
  3471. { et.al.char.used
  3472.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  3473.     'skip$
  3474.   if$
  3475.   preamble$ empty$
  3476. #else !LAB_ALPH
  3477. { preamble$ empty$
  3478. #endif LAB_ALPH
  3479.     'skip$
  3480.     { preamble$ write$ newline$ }
  3481.   if$
  3482.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  3483. }
  3484. #else NAMED_REFS
  3485. { preamble$ empty$                              % no \etalchar in apalike
  3486.     'skip$
  3487.     { preamble$ write$ newline$ }
  3488.   if$
  3489.   "\begin{thebibliography}{}" write$ newline$           % no labels in apalike
  3490. }
  3491. #endif NAMED_REFS
  3492.  
  3493. EXECUTE {begin.bib}
  3494.  
  3495. EXECUTE {init.state.consts}
  3496.  
  3497. % Now we produce the output for all the entries
  3498.  
  3499. ITERATE {call.type$}
  3500.  
  3501. % Finally, we finish up by writing the `\end{thebibliography}' command.
  3502.  
  3503. FUNCTION {end.bib}
  3504. { newline$
  3505.   "\end{thebibliography}" write$ newline$
  3506. }
  3507.  
  3508. EXECUTE {end.bib}
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.